"""Redis SDB module================ .. versionadded:: 2019.2.0This module allows access to Redis using an ``sdb://`` URI.Like all SDB modules, the Redis module requires a configuration profile tobe configured in either the minion or master configuration file. This profilerequires very little. For example:.. code-block:: yaml sdb_redis: driver: redis host: 127.0.0.1 port: 6379 password: pass db: 1The ``driver`` refers to the Redis module, all other options are optional.For option details see: https://redis-py.readthedocs.io/en/latest/."""try:importredisHAS_REDIS=TrueexceptImportError:HAS_REDIS=False__func_alias__={"set_":"set"}__virtualname__="redis"
[docs]def__virtual__():""" Module virtual name. """ifnotHAS_REDIS:return(False,"Please install python-redis to use this SDB module.")return__virtualname__
[docs]defset_(key,value,profile=None):""" Set a value into the Redis SDB. """ifnotprofile:returnFalseredis_kwargs=profile.copy()redis_kwargs.pop("driver")redis_conn=redis.StrictRedis(**redis_kwargs)returnredis_conn.set(key,value)
[docs]defget(key,profile=None):""" Get a value from the Redis SDB. """ifnotprofile:returnFalseredis_kwargs=profile.copy()redis_kwargs.pop("driver")redis_conn=redis.StrictRedis(**redis_kwargs)returnredis_conn.get(key)
[docs]defdelete(key,profile=None):""" Delete a key from the Redis SDB. """ifnotprofile:returnFalseredis_kwargs=profile.copy()redis_kwargs.pop("driver")redis_conn=redis.StrictRedis(**redis_kwargs)returnredis_conn.delete(key)