网站建设资讯

NEWS

网站建设资讯

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的基本操作
文章转载:http://cdweb.net/article/gphdhc.html