speed up loading and saving to redis that the move request are getting a answer when switching workers, strip data that neats to get recomuted every turn
Build and Push Docker Container / build-and-push (push) Successful in 4m49s
Build and Push Docker Container / build-and-push (push) Successful in 4m49s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from typing import TYPE_CHECKING
|
||||
import inspect, pickle
|
||||
import inspect, pickle, zlib
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from server.GameBoard import GameBoard
|
||||
@@ -28,7 +28,7 @@ class RedisGameBoardStore:
|
||||
|
||||
async def save(self, game_id:str, game_board:'GameBoard') -> None:
|
||||
redis = await self._get_redis()
|
||||
payload = pickle.dumps(game_board, protocol=pickle.HIGHEST_PROTOCOL)
|
||||
payload = zlib.compress(pickle.dumps(game_board, protocol=pickle.HIGHEST_PROTOCOL), level=1)
|
||||
await redis.set(self._key(game_id), payload, ex=self.ttl_seconds)
|
||||
|
||||
async def load(self, game_id:str):
|
||||
@@ -36,7 +36,10 @@ class RedisGameBoardStore:
|
||||
payload = await redis.get(self._key(game_id))
|
||||
if payload is None:
|
||||
return None
|
||||
return pickle.loads(payload)
|
||||
try:
|
||||
return pickle.loads(zlib.decompress(payload))
|
||||
except zlib.error:
|
||||
return pickle.loads(payload)
|
||||
|
||||
async def delete(self, game_id:str) -> None:
|
||||
redis = await self._get_redis()
|
||||
|
||||
Reference in New Issue
Block a user