servers module#
- class servers.Server(*arg, **kwargs)[source]#
Bases:
redis.client.RedisSubclass of Redis object, aiming to simplify the use of the server to few basic commands.
- Parameters
args – arguments passed to parent constructor
kwargs – keyword arguments passed to parent constructor
- Example
>>> s = Server(host='localhost', port=6379)
- get_multiple_values(*keys: str, prefix: str = '', **kwargs) Tuple[Dict[str, Any], List[str]][source]#
Returns all the values corresponding the given keys. If key does not match any value, the key is returned explicitly tell that it is missing. An optional prefix can be added to every key.
- get_multiple_values_expired(*keys: str, prefix: str = '') Tuple[Dict[str, Optional[bool]]][source]#
Returns, for each key, wether a expire notification was issued or not, and None is returned if the case the key does not exist. An optional prefix can be added to every key.
- get_value(key: str, hmap: Optional[str] = None) Any[source]#
Returns the value with corresponding key stored in the server.
- Parameters
- Returns
the object stored in the server, None if not object matching the key
- Return type
Any
- Example
>>> s.get_value('apple') {'weight': 400, 'unit': 'g'}
- is_running() bool[source]#
Checks whether the server is running.
- Returns
True if the server is running
- Return type
- run()[source]#
Runs the server. Since redis is an externally run server, it cannot be started from the python code properly.
- set_value(key: str, value: Any, expire_in: Optional[Dict[str, int]] = None, notify_expire_in: Optional[Dict[str, int]] = None, hmap: bool = False)[source]#
Store a pair key / value in the server, with an optional expiration time.
- Parameters
- Example
>>> s.set_value('apple', {'weight': 400, 'unit': 'g'}, expire_in={'hours': 10})
- servers.parse_redis_ttl_config(conf: Mapping[str, str]) Dict[str, Dict[str, int]][source]#
Parses a config mapping (from a config file for example) into a usable TTL config. Each key, value pair holds the name of the resource stored in the server and the parameters to setup the default expiry duration.