Skip to content

Commit 8de4afb

Browse files
author
Will
authored
Create into_redis.py
1 parent 7ca310b commit 8de4afb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

‎will/0003/into_redis.py‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# 第 0003 题: 将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。
2+
importrandom, string, time, math, uuid, redis
3+
4+
chars=string.ascii_letters+string.digits
5+
6+
defgen1():
7+
key=''.join(random.sample(chars, 10))
8+
#key2 = ''.join(random.choice(chars) for i in range(10))
9+
returnkey
10+
11+
defgen2():
12+
key=math.modf(time.time())[0]
13+
returnkey
14+
15+
defgen3():
16+
returnuuid.uuid4()
17+
18+
if'__name__'=='__main__':
19+
r=redis.Redis(host='localhost', port=6379, db=0)
20+
# r.set('name', 'will')
21+
# print(r.get('name'))
22+
foriinrange(200):
23+
r.sadd('code', gen1())
24+
r.save()

0 commit comments

Comments
(0)