美文网首页
Python 使用redis 集群

Python 使用redis 集群

作者: ScottX | 来源:发表于2017-06-13 00:57 被阅读464次

在redis2版本时, python在使用redis 的时候,只需要

import redis

即可建立起Redis连接,并且进行使用。如果在使用Redis Cluster的时候则不能使用该方法。

首先得安装 redis-py-cluster

sudo pip install redis-py-cluster

连接方面代码改为:

from rediscluster import StrictRedisCluster
import sys
def redis_cluster(name='default'):
redis_nodes = [{'host':'127.0.0.1','port':7000},
{'host':'127.0.0.1','port':7001}
]
try:
redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
return redisconn
except Exception,e:
print "Connect Error!"
sys.exit(1)

相关文章

网友评论

      本文标题:Python 使用redis 集群

      本文链接:https://www.haomeiwen.com/subject/gpwrqxtx.html