redis的cluster(分布式or分片)

1.创建配置文件:
    /data/cluster目录下创建6个redis配置
2.逐个配置
    port  7001
    添加:
            daemonize yes
            cluster-enabled yes
            cluster-config-file redis-7001.conf
            cluster-node-timeout 5000
            appendonly yes #只读
3.依次启动redis实例
    redis-server /data/cluster/redis-7001.conf
4.获取分布式脚本 是ruby写的
    安装依赖 ruby>2.2.2版本
        yum install ruby rubygems -y
        gem sources --add https//gems.ruby-china.com/  #更换源
        升级
            gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
                curl -sSL https://get.rvm.io | bash -s stable
                source /usr/local/rvm/scripts/rvm
                rvm list known
                rvm install 2.5.1
                rvm use 2.5.1
                rvm remove 2.0.0
                ruby --version
            重新安装 gem install redis
拷贝redis-trib.rb到/data/cluster目录
运行ruby脚本
./redis-trib.rb reshared ip:port (你的IP地址)

8.python连接redis-cluster 
    pip3 install redis-py-cluster

from rediscluster import strictRedisCluster
startup_nodes = [
    {"host": "127.0.0.1", "port": "6379"},
]
rc = StrictRedisCluster(startup_nodes=startup_nodes, decode_responses=True)

# 字符串操作
rc.set("foo", "bar")
print(rc.get("foo"))

 

posted @ 2019-06-21 16:24  coding天荒地老  阅读(309)  评论(0编辑  收藏  举报