<s> from django . core . exceptions import ImproperlyConfigured <EOL> from flows . statestore . base import StateStoreBase , StateNotFound <EOL> from flows import config <EOL> try : <EOL> import redis <EOL> except ImportError : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' ) <EOL> class StateStore ( StateStoreBase ) : <EOL> def _get_settings ( self ) : <EOL> host = config . FLOWS_REDIS_STATE_STORE_HOST <EOL> password = config . FLOWS_REDIS_STATE_STORE_PASSWORD <EOL> port = config . FLOWS_REDIS_STATE_STORE_PORT <EOL> db_id = config . FLOWS_REDIS_STATE_STORE_DB <EOL> return { '<STR_LIT:host>' : host , '<STR_LIT:port>' : port , <EOL> '<STR_LIT:password>' : password , '<STR_LIT>' : db_id } <EOL> def _get_db ( self ) : <EOL> return redis . Redis ( ** self . _get_settings ( ) ) <EOL> def get_state ( self , task_id ) : <EOL> data = self . _get_db ( ) . get ( task_id ) <EOL> if not data : <EOL> raise StateNotFound <EOL> return self . _deserialise ( data ) <EOL> def put_state ( self , task_id , state ) : <EOL> ttl = config . FLOWS_TASK_IDLE_TIMEOUT <EOL> data = self . _serialise ( state ) <EOL> self . _get_db ( ) . setex ( task_id , data , ttl ) <EOL> def delete_state ( self , task_id ) : <EOL> self . _get_db ( ) . delete ( task_id ) </s>
