We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7ca310b commit 8de4afbCopy full SHA for 8de4afb
1 file changed
will/0003/into_redis.py
@@ -0,0 +1,24 @@
1
+# 第 0003 题: 将 0001 题生成的 200 个激活码(或者优惠券)保存到 Redis 非关系型数据库中。
2
+import random, string, time, math, uuid, redis
3
+
4
+chars = string.ascii_letters + string.digits
5
6
+def gen1():
7
+ key = ''.join(random.sample(chars, 10))
8
+ #key2 = ''.join(random.choice(chars) for i in range(10))
9
+ return key
10
11
+def gen2():
12
+ key = math.modf(time.time())[0]
13
14
15
+def gen3():
16
+ return uuid.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
+ for i in range(200):
23
+ r.sadd('code', gen1())
24
+ r.save()
0 commit comments