1. 程式人生 > >python對redis的基本操作

python對redis的基本操作

set pytho ctr def aof 處理 ict local odin

#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

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的基本操作