diff --git a/app.py b/app.py index 2aee395..e307140 100644 --- a/app.py +++ b/app.py @@ -3,7 +3,7 @@ from multiprocessing import Process from settings import settings from v2 import * -from v2.struct_cache import StructCacheFile +from v2.struct_cache import StructCacheFile, StructCacheRedis class XProcess(Process): @@ -16,7 +16,7 @@ class XProcess(Process): def run(self): db_client = CK(**settings.CK_CONFIG) - sketch = Sketch(db_client, StructCacheFile()) + sketch = Sketch(db_client, StructCacheRedis()) handler_event = HandlerEvent(db_client, settings.GAME, self.ipsearch) handler_user = HandlerUser(db_client, settings.GAME) transmitter = Transmitter(db_client, settings.GAME, sketch, self.lock) diff --git a/settings.py b/settings.py index 56e57c5..51bcd49 100644 --- a/settings.py +++ b/settings.py @@ -20,12 +20,13 @@ class Config: # 游戏数据库名 GAME = 'shjy' - # REDIS_CONF = { - # 'host': '192.168.0.161', - # 'port': 6379, - # 'password': 'd1Gh*zp5', - # 'ck': 10 # ck - # } + REDIS_CONF = { + 'host': '192.168.0.161', + 'port': 6379, + 'password': 'd1Gh*zp5', + 'db': 1, # 存表结构 + 'decode_responses':True + } class Debug(Config): diff --git a/v2/struct_cache.py b/v2/struct_cache.py index 17f06ec..b397498 100644 --- a/v2/struct_cache.py +++ b/v2/struct_cache.py @@ -1,4 +1,7 @@ import json +import redis + +from settings import settings class StructCacheFile: @@ -9,3 +12,11 @@ class StructCacheFile: def update(db, tb, data): with open(f'{db}_{tb}.json', 'w') as f: json.dump(data, f) + + +class StructCacheRedis: + def __init__(self): + self.rdb = redis.Redis(**settings.REDIS_CONF) + + def update(self, db, tb, data): + self.rdb.set(f'{db}_{tb}', json.dumps(data))