@@ -0,0 +1,1850 @@
+from flask_helpers.ErrorHandler import ErrorHandler%0Aimport redis%0A%0A%0Aclass Persister:%0A    _redis_connection = None%0A%0A    def __init__(self, host=%22localhost%22, port=6379, db=0):%0A        self.handler = ErrorHandler(%0A            module=%22RedisPersist%22,%0A            method=%22__init__%22,%0A        )%0A%0A        self.handler.log(message=%22Preparing redis connection%22)%0A        self._redis_connection = redis.StrictRedis(%0A            host=host,%0A            port=port,%0A            db=db%0A        )%0A%0A        self.handler.log(message=%22Testing redis connection with dummy key%22)%0A        self._redis_connection.set('tmp_validate', 'tmp_validate', ex=60)%0A%0A    def save(self, key=None, jsonstr=None):%0A        self.handler.method = %22save%22%0A%0A        self.handler.log(message=%22Validating key: %7B%7D%22.format(key))%0A        if key is None:%0A            raise ValueError(%22Key must be present to persist game.%22)%0A%0A        self.handler.log(message=%22Validating json: %7B%7D%22.format(jsonstr))%0A        if jsonstr is None:%0A            raise ValueError(%22JSON is badly formed or not present%22)%0A%0A        self.handler.log(message=%22Setting key %7B%7D in redis%22.format(key))%0A        self._redis_connection.set(str(key), str(jsonstr), ex=(60*60))%0A        self.handler.log(message=%22Key set.%22)%0A%0A    def load(self, key=None):%0A        self.handler.method = %22load%22%0A%0A        self.handler.log(message=%22Validating key: %7B%7D%22.format(key))%0A        if key is None:%0A            raise ValueError(%22Key must be present to execute_load game%22)%0A%0A        self.handler.log(message=%22Fetching key: %7B%7D%22.format(key))%0A        return_result = self._redis_connection.get(key)%0A        if return_result is not None:%0A            if isinstance(return_result, bytes):%0A                return_result = str(return_result.decode('utf-8'))%0A%0A        self.handler.log(message=%22Key %7B%7D returned: %7B%7D%22.format(key, return_result))%0A        return return_result%0A

Add Redis package