-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash_set_reset.py
33 lines (29 loc) · 975 Bytes
/
hash_set_reset.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
# -*- coding: utf-8 -*-
import os
import redis
import json
from dotenv import load_dotenv
# 加载 .env 文件
load_dotenv()
# 连接Redis数据库
host = os.getenv('REDIS_HOST')
port = int(os.getenv('REDIS_PORT'))
db = int(os.getenv('REDIS_DB'))
password = os.getenv('REDIS_PASS')
print(host, port, db, password)
redis_pool = redis.Redis(host=host, port=port, db=db, password=password)
def reset_counts():
for key in redis_pool.hkeys("hash_db"):
value = redis_pool.hget("hash_db", key)
if value:
value_dict = json.loads(value)
value_dict["count"] = 50
redis_pool.hset("hash_db", key, json.dumps(value_dict))
for key in redis_pool.hkeys("gpt4plus"):
value = redis_pool.hget("gpt4plus", key)
if value:
value_dict = json.loads(value)
value_dict["count"] = 20
redis_pool.hset("gpt4plus", key, json.dumps(value_dict))
if __name__ == '__main__':
reset_counts()