redis+twemproxy自动分片(一致性hash)

来源:互联网 发布:网络虚拟电话软件 编辑:程序博客网 时间:2024/05/17 02:13
一、采用Node.js编写测试脚本(myproxy.js)
var redis = require('redis');var options = {   "no_ready_check": true,};var client = redis.createClient(22121, 'localhost', options); var alphabet = [  'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',  'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',  'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']; alphabet.forEach(function(letter) {   client.set(letter, letter); });client.quit(); 

二、分别开启3台Redis服务器

redis-server --port 2222--daemonize yes

redis-server --port 3333--daemonize yes

redis-server --port 4444--daemonize yes

三、分别开启3台Redis客户端,并且开启监控

[root@localhost ~]# redis-cli -p 2222
127.0.0.1:2222> MONITOR

OK

[root@localhost ~]# redis-cli -p 3333
127.0.0.1:3333> MONITOR

OK

[root@localhost ~]# redis-cli -p 4444
127.0.0.1:4444> MONITOR

OK

开启twemproxy集群

my_cluster:  listen: 127.0.0.1:22121  hash: md5  distribution: ketama  auto_eject_hosts: true  redis: true  servers:    - 127.0.0.1:2222:1 server1    - 127.0.0.1:3333:1 server2    - 127.0.0.1:4444:1 server3

五、运行Node脚本,输出如下:



1 0
原创粉丝点击