发布时间:2019-09-07 08:08:10编辑:auto阅读(1625)
import redis
"""
连接redis ConnectionPool 方式连接
"""
def connRedis(self):
pool=redis.ConnectionPool(host='172.16.1.2',password='',db=2, port=6379) #按具体情况填写参数
r=redis.StrictRedis(connection_pool=pool)
r.set("test_name","admin")
print(r.get('test_name'))
python 操作redis 集群 用redis模块不行,需要导入模块
# pip install redis-py-cluster
#!/usr/bin/env python
#coding:utf-8
from rediscluster import StrictRedisCluster
import sys
def redis_cluster():
redis_nodes = [{'host':'192.168.1.2','port':6378},
{'host':'192.168.1.2','port':6380},
{'host':'192.168.1.2','port':6381},
{'host':'192.168.1.2','port':6382},
{'host':'192.168.1.2','port':6383},
{'host':'192.168.1.2','port':6384},
{'host':'192.168.1.2','port':6385}
]
try:
redisconn = StrictRedisCluster(startup_nodes=redis_nodes)
except Exception,e:
print "Connect Error!"
sys.exit(1)
redisconn.set('name','admin')
print "name is: ", redisconn.get('name')
redis_cluster()
上一篇: MyEclipse和Eclipse中配置
下一篇: python udp 广播
48853
47914
38702
35853
30280
27027
26063
20894
20692
19059
492°
585°
600°
604°
581°
567°
628°
701°
824°
921°