Python:redis与Python交互(Redis二)
#!/usr/bin/env python# coding:UTF-8"""@version: python3.x@author:曹新健@contact: 617349013@qq.com@software: PyCharm@file: redis与Python交互.py@time: 2018/9/24 20:47"""import re
·
#!/usr/bin/env python
# coding:UTF-8
"""
@version: python3.x
@author:曹新健
@contact: 617349013@qq.com
@software: PyCharm
@file: redis与Python交互.py
@time: 2018/9/24 20:47
"""
import redis
#连接
conn = redis.StrictRedis(host="localhost",port=6379,password="cxj123456")
#方法1:根据数据类型的不同,调用相应的方法
'''
#写
conn.set("p1","good")
#读
print(conn.get("p1"))
'''
#方法2 pipline
#缓冲多条命令,然后依次执行,减少服务器与客户端之间的TCP数据包
pipe = conn.pipeline()
pipe.set("p2","nice")
pipe.set("p3","handsome")
pipe.set("p4","cool")
pipe.execute()
更多推荐
已为社区贡献51条内容
所有评论(0)