Python redis

来自牛奶河Wiki
阿奔讨论 | 贡献2023年12月19日 (二) 16:42的版本 (创建页面,内容为“===单机=== # 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…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳到导航 跳到搜索

单机

# 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')