python對redis的基本操作
阿新 • • 發佈:2018-08-06
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 pipline.set("ldh","liudehua")
pipline.execute()
except Exception,e:
print e
main()
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:
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.execute()
except Exception,e:
print e
main()
python對redis的基本操作