Python 官方文档:入门教程 => 点击学习
python 操作Redis 需要导入redis模块import redis """ 连接redis ConnectionPool 方式连接 """ def connRedis(self):
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()
--结束END--
本文标题: python 操作 redis,redi
本文链接: https://www.lsjlt.com/news/188433.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0