Python redis
跳到导航
跳到搜索
单机
# pip3 install redis import redis rs = redis.Redis(host='192.168.0.229', port=6379, password=, db=0) # Conn Pool #rsp = redis.ConnectionPool(host='192.168.0.229', port=6379, password=, db=0) #rs = redis.Redis(connection_pool = rsp) # 有效时间 100 secs # rs.set('test', 'Hello, World!', 100) rs.set('test', 'Hello, World!') rs.get('test')
集群
# pip3 install redis-py-cluster from rediscluster import RedisCluster rnode = [ {"host": "192.168.0.229", "port": 6379}, {"host": "192.168.0.229", "port": 6380}, {"host": "192.168.0.148", "port": 6379}, {"host": "192.168.0.148", "port": 6380}, {"host": "192.168.0.249", "port": 6379}, {"host": "192.168.0.249", "port": 6380} ] rs = RedisCluster(startup_nodes=rnode, decode_responses=True) rs.get('test')