-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis_test.py
More file actions
37 lines (32 loc) · 954 Bytes
/
redis_test.py
File metadata and controls
37 lines (32 loc) · 954 Bytes
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
# -*- coding: utf-8 -*- 运行python
import redis,os
pool = redis.ConnectionPool(host='10.1.42.132', port=6379)
#pool = redis.ConnectionPool(host='39.108.109.58', port=6379)
#pool = redis.ConnectionPool(host='10.1.246.1', port=6379)
conn = redis.Redis(connection_pool=pool)
def main():
keys = conn.keys()
for k in keys:
print(k)
def get_all_file(path='.\\',not_in=[]):
lst=[]
dirs=os.listdir(path)
for d in dirs:
if os.path.isfile(d) and d not in not_in:
lst.append(d)
return lst
def upload(conn,name,lst,delete=False):
if delete:
conn.delete(name)
for file in lst:
with open(file,'rb') as f:
res=f.read()
conn.hset(name,file,res)
print('update:'+file)
def download(conn,name):
keys=conn.hkeys(name)
for key in keys:
with open(key,'wb') as f:
f.write(conn.hget(name,key))
if __name__ == '__main__':
main()