python对redis的基本操作
#coding:utf8
from redis import StrictRedis
"""定义一个处理redis的类"""
class OprRedis:
def init(self,host,port):
self._redis = StrictRedis(host,port)
def set(self,key,value):
try:
self._redis.set(key,value)
except Exception,e:
print e
def get(self,key):
try:
return self._redis.get(key)
except Exception,e:
print e
def pipeline(self):
try:
return self._redis.pipeline(transaction=False)
except Exception,e:
print e
创新互联主要从事成都网站设计、网站制作、网页设计、企业做网站、公司建网站等业务。立足成都服务宝兴,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
def main():
oprRedis = OprRedis("localhost","6379")
oprRedis.set("wf","wangfei")
print oprRedis.get("xjb")
pipline = oprRedis.pipeline()
try:
pipline.set("xxf","xiaoxiaofang")
pipline.set("ldh","liudehua")
pipline.execute()
except Exception,e:
print e
main()
当前标题:python对redis的基本操作
文章URL:http://ybzwz.com/article/gphdhc.html