Commit 8b2c8e3a by 岳巧源

add

parent fea79eb5
Showing with 24 additions and 4 deletions
import random
import time
import redis
pool = redis.ConnectionPool(host='10.8.0.6', port=6379)
class Utils:
def save_kv_to_redis(self, key: str, value: dict):
conn = redis.Redis(connection_pool=pool)
conn.hset(name=key, mapping=value)
class User:
def __init__(self, name="admin", password="admin@123"):
def __init__(self, name="admin", password="admin@123", ip="127.0.0.1"):
self.uid = self.generate_uid()
self.name = name
self.password = password
self.ip = ip
self.register_time = int(time.time())
def generate_uid(self) -> str:
timestamp = time.time()
......@@ -23,6 +34,15 @@ class User:
if __name__ == '__main__':
u = User()
print(u.uid)
print(len(u.uid))
for i in range(1000):
u = User()
util = Utils()
data = {
"name": u.name,
"password": u.password,
"ip": u.ip,
"create_time": u.register_time
}
util.save_kv_to_redis(u.uid, data)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment