redis主从复制

1关于redis的原理
2怎样进行主从复制
设置配置文件的slaveof打开2。监听端口6379
[root@localhost redis-2.0.4]# cp redis.conf redis_master.conf
[root@localhost redis-2.0.4]# cp redis.conf redis_slave.conf
[root@localhost redis-2.0.4]# vi redis_master.conf
daemonize yes
[root@localhost redis-2.0.4]# vi redis_slave.conf
daemonize yes
port 6389
slaveof localhost 6379
[root@localhost redis-2.0.4]# cp {redis_master.conf,redis_slave.conf} /etc
[root@localhost etc]# redis-server /etc/redis_master.conf
[root@localhost etc]# redis-server /etc/redis_slave.conf
@localhost etc]# ps aux
    24983  0.0  0.1  12004  1720 ?        Ss   05:36   0:00 redis-server /etc/redis_slave.conf
root     25012  0.0  0.1   9900  1480 ?        Ss   05:39   0:00 redis-server /etc/redis_master.conf
root     25018  0.0  0.0 103252   832 pts/0    S+   05:40   0:00 grep redis
[root@localhost etc]# telnet localhost 6379
t: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
rpush dat 1
1
:1
lrange dat 0 -1
*2
$1
1
$1
2


oot@localhost etc]# telnet localhost 6389
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
lrange dat 0 -1
*2
$1
1
$1
2
13:25
开发语言                  程序库
ruby                        redis-rb
perl                        redis
java                        jedis,jredis
c                            hiredis
php                          predis ,phpredis
scala                         scala-redis
object-c                      objCredis
node.js                       node_redis,redis-node client
clojure                       redis-clojune
3怎么样组件集群
[root@localhost etc]# cp redis.conf redis_6379.conf
[root@localhost etc]# cp redis.conf redis_6380.conf
[root@localhost etc]# vi redis_6380.conf
port 6380
[root@localhost etc]# cp redis.conf redis_6381.conf
[root@localhost etc]# vi redis_6381.conf
port 6381
[root@localhost etc]# redis-server /etc/redis_6379.conf
[root@localhost etc]# redis-server /etc/redis_6380.conf
[root@localhost etc]# redis-server /etc/redis_6381.conf
t@localhost etc]# ps aux
root      2780  0.0  0.1   9900  1424 ?        Ss   17:59   0:00 redis-server /e
root      2783  0.0  0.1   9900  1420 ?        Ss   17:59   0:00 redis-server /e
root      2785  0.0  0.1   9900  1424 ?        Ss   17:59   0:00 redis-server /e



require 'rubygems'
require 'redis'
require 'redis/distributed'

redis=Redis::Distributed.new %W(redis::/localhost:6379 redis::/localhost:6380 redis::/localhost:6381)
(1..20).each do|n|
redis.set "key_#{n}","value_#{n}"
end
redis.ring.nodes.each do |node|
p "#{node.client.host}:#{node.client.port}:#{node.keys("*").join(',')}"
end

4各种数据怎么样操作,在使用上有事吗便利之处redis cookbook
memchache保存的是字节流
[root@localhost redis-2.0.4]# ./redis-cli -p 6379
场景一保存点击数据计算器
redis> set visits:1:totals 2134
OK
redis> set visits:2:totals 21365
OK
redis> incr visits:635:totals;
(integer) 1
redis> incr visits:635:totals;
(integer) 2
redis> get visits:635:totals;
"2"
场景二在hash表里面保存数据
redis> hset users:jdoe name "john doe"

Reconnecting... OK
(integer) 1
redis> hset users:jdoe email "[email protected]"
(integer) 1
redis> hset users:jdoe phone "+13212131"
(integer) 1
redis> hget users:jdoe email
"[email protected]"
redis> hgetall users:jdoe
1. "name"
2. "john doe"
3. "email"
4. "[email protected]"
5. "phone"
6. "+13212131"
redis>
edis> hkeys users:jdoe
1. "name"
2. "email"
3. "phone"
redis> hvals users:jdoe
1. "john doe"
2. "[email protected]"
3. "+13212131"
场景三:用集合保存社交网站圈子数据

redis> sadd circle:jdoe:family users:nike
(integer) 1
redis> sadd circle:jdoe:family users:mike
(integer) 1
redis> sadd circle:jdoe:family users:adam
(integer) 1
redis> sadd circle:jdoe:family users:toby
(integer) 1
redis> sadd circle:jdoe:family users:apollo
(integer) 1
redis> sadd circle:jdoe:soccer users:apollo
(integer) 1
redis> sadd circle:jdoe:soccer users:toby
(integer) 1

redis> smembers circle:jdoe:family
1. "users:adam"
2. "users:nike"
3. "users:toby"
4. "users:mike"
5. "users:apollo"
redis> smembers circle:jdoe:soccer
1. "users:apollo"
2. "users:mike"
3. "users:toby"
redis> sinter circle:jdoe:family circle:jdoe:soccer
1. "users:apollo"
2. "users:mike"
3. "users:toby"

redis> sunion circle:jdoe:family circle:jdoe:soccer
1. "users:nike"
2. "users:apollo"
3. "users:adam"
4. "users:mike"
5. "users:toby"




5适合那些应用场景
6redis实现原理
7redis的安全性
8redis怎么样处理大数据,比如说对内存







root@localhost redis-2.0.4]# ./redis-cli INFO
redis_version:2.0.4
redis_git_sha1:00000000
redis_git_dirty:0
arch_bits:64
multiplexing_api:epoll
process_id:2780
uptime_in_seconds:2382
uptime_in_days:0
connected_clients:1
connected_slaves:0
blocked_clients:0
used_memory:783192
used_memory_human:764.84K
changes_since_last_save:0
bgsave_in_progress:0
last_save_time:1453427973
bgrewriteaof_in_progress:0
total_connections_received:1
total_commands_processed:0
expired_keys:0
hash_max_zipmap_entries:64
hash_max_zipmap_value:512
pubsub_channels:0
pubsub_patterns:0
vm_enabled:0
role:master
db0:keys=3,expires=0

你可能感兴趣的:(redis主从复制)