"""$ pip install redis"""
from redis import StrictRedis
if __name__ == '__main__':
connection = StrictRedis(host="localhost", port=6379, db=0, )
result = connection.set("key1", "value1")
print(result)
print(connection.get("key1"))
"""
Latest stable release from pypi
$ pip install redis-py-cluster
注意:This major version of redis-py-cluster supports redis-py >=3.0.0, <4.0.0.
"""
from rediscluster import RedisCluster
if __name__ == '__main__':
node_list = [
{"host": "192.168.1.187", "port": "7000"},
{"host": "192.168.1.187", "port": "7001"},
{"host": "192.168.1.187", "port": "7002"},
{"host": "192.168.1.188", "port": "7003"},
{"host": "192.168.1.188", "port": "7004"},
{"host": "192.168.1.188", "port": "7005"}
]
connection = RedisCluster(startup_nodes=node_list, decode_responses=True)
result = connection.set("key1", "value1")
print(result)
print(connection.get("key1"))