class myRedis(object):
def __init__(self,redis_type=None,**args):
if redis_type == "cluster":
import rediscluster
self.r_conn = rediscluster.StrictRedisCluster(**args)
else:
import redis
self.r_conn = redis.StrictRedis(**args)
def GetValue(self,name):
return self.r_conn.get(name)
def IncrValue(self,name):
return self.r_conn.incr(name)
def SetValue(self,name,value):
self.r_conn.set(name,value)
def GetSetValue(self,name,value):
return self.r_conn.getset(name,value)
if __name__ == '__main__':
#cluster
conn_dict={"startup_nodes":[{'host':'10.200.22.110', 'port':16379},{'host':'10.200.22.110', 'port':26379},{'host':'10.200.22.110', 'port':36379}]}
redis_type='cluster'
myredis = myRedis(redis_type,**conn_dict)
print(myredis.SetValue('name','test'))
print(myredis.GetValue('name'))
从网络上搜索到的脚本,但遗憾的是本地验证不通过,每次执行到 rediscluster.StrictRedisCluster(**args) 即停止了,留待后面解决