import redis #导包
class Myredis:
def __init__(self,db=0,decode_responses=False):#使用0号数据库
#打印中文会显示bytes
self.conn = redis.StrictRedis(db=db,decode_responses=True)
def push(self,key,*args,direction = 'r'):
if direction == 'r':
self.conn.rpush(key,*args)
else:
self.conn.lpush(key, *args)
def research(self,key,start,end=None):
if end:
return self.conn.lrange(key, start, end)
else:
return self.conn.lindex(key, start)
def dele(self,key,direction='r'):
if (direction == 'r'):
return self.conn.lpop(key)
else:
return self.conn.rpop(key)
def change(self,key,index,value):
self.conn.lset(key,index,value)
if __name__ == '__main__':
wangzi = Myredis(db=0, decode_responses=True)
# wangzi.push('key','wangzi','is','da','shuaige',direction = 'r')
# print(wangzi.research('key',0,-1))
# print(wangzi.dele('key','direction' == 'r'))
# wangzi.change('key',0,'woshizhendeshuaide yi pi')