forked from JoneXiong/PyRedisAdmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_change.py
53 lines (46 loc) · 1.31 KB
/
data_change.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# coding=utf-8
import config
def delete_key(key,cl, cursor=None):
if cursor!=None:
key = key + '*'
next_cursor,m_all = cl.scan(cursor=cursor, match=key, count=config.scan_batch)
for e in m_all:
cl.delete(e)
else:
cl.delete(key)
def delete_value(key,value,type,cl):
if type=="hash":
cl.hdel(key, value)
elif type=="list":
cl.lset(key, value, '__delete__')
cl.lrem(key, '__delete__', 0)
elif type=="set":
cl.srem(key, value)
elif type=="zset":
cl.zrem(key, value)
def rename_key(key,new,cl):
cl.rename(key,new)
def edit_value(key,value,new,score,type,cl):
if type=="hash":
cl.hset(key,value,new)
elif type=="list":
cl.lset(key, value, new)
elif type=="set":
cl.srem(key, value)
cl.sadd(key, new)
elif type=="zset":
cl.zrem(key, value)
cl.zadd(key,new,float(score) )
elif type=="string":
cl.set(key, new)
def add_value(key,value,name,score,type,cl):
if type=="hash":
cl.hset(key,name,value)
elif type=="list":
cl.rpush(key, value)
elif type=="set":
cl.sadd(key, value)
elif type=="zset":
cl.zadd(key,value,float(score) )
def change_ttl(key,new,cl):
cl.expire(key,new)