Skip to content
Snippets Groups Projects
Commit 5deb264f authored by sguazt's avatar sguazt
Browse files

Redis: added configuration parameters for Redis's authentication

parent d580a9e1
No related branches found
No related tags found
No related merge requests found
......@@ -32,13 +32,14 @@ class RedisSink(measures_sink.MeasuresSink):
- redis-py Python client: https://github.com/andymccurdy/redis-py
"""
DEFAULT_DB = 0
DEFAULT_PASSWORD = None
DEFAULT_URL = 'redis://localhost:6379/'
DEFAULT_DB = None
DEFAULT_USERNAME = None
@classmethod
def from_conf(cls, conf):
#FIXME: the Redis client will throw an exception if kwargs contains unrecognized options
# Thus, for now, we are commenting this code below and we just pass only the url and db options to Redis
# In the future, we will look for the following parameters in the conf explicitly:
# host='localhost',
# port=6379,
......@@ -67,8 +68,9 @@ class RedisSink(measures_sink.MeasuresSink):
# client_name=None,
# username=None
# See https://redis.io and https://github.com/andymccurdy/redis-py/ for the meaning of those parameters.
url = None
db = None
password = None
url = None
kwargs = dict()
#logging.debug("FROM CONF {}".format(conf))
#for key in conf:
......@@ -78,17 +80,27 @@ class RedisSink(measures_sink.MeasuresSink):
# db = conf['db']
# else:
# kwargs[key] = conf[key]
if 'url' in conf:
url = conf['url']
if 'db' in conf:
db = conf['db']
return cls(url=url, db=db, **kwargs)
if 'password' in conf:
url = conf['password']
if 'url' in conf:
url = conf['url']
if 'username' in conf:
url = conf['username']
return cls(url=url, db=db, username=username, password=password, **kwargs)
def __init__(self, url=DEFAULT_URL, db=DEFAULT_DB, **kwargs):
def __init__(self, url=DEFAULT_URL, db=DEFAULT_DB, username=DEFAULT_USERNAME, password=DEFAULT_PASSWORD, **kwargs):
super(RedisSink, self).__init__()
self._url = url if (url is not None) and len(url) > 0 else self.DEFAULT_URL
self._db = db if (db is not None) and len(db) > 0 else self.DEFAULT_DB
self._redis = redis.Redis.from_url(url=self._url, db=self._db, **kwargs)
self._url = url if url else self.DEFAULT_URL
self._db = db if db else self.DEFAULT_DB
self._username = username if username else self.DEFAULT_USERNAME
self._password = password if password else self.DEFAULT_PASSWORD
self._redis = redis.Redis.from_url(url=self._url,
db=self._db,
username=self._username,
password=self._password,
**kwargs)
def put(self, measure):
msg_key = self._measure_group_encode(self._measure_group(measure))
......
......@@ -227,8 +227,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -227,8 +227,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -178,8 +178,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -178,8 +178,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -252,8 +252,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -252,8 +252,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -169,8 +169,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
......@@ -169,8 +169,15 @@ exchange = easycloud
module = core.measures_sink.redis
class = RedisSink
# The URL to the Redis server (see `redis.from_url()` at https://redis-py.readthedocs.io/en/latest/)
# Note, if the URL specifies also the database, the username, and the password, the following configuration parameters ``db``, ``username`` and ``password`` will be ignored.
# Default: redis://localhost:6379/
url = redis://localhost:6379/
# The db parameter is the database number. You can manage multiple databases in Redis at once, and each is identified by an integer. The max number of databases is 16 by default
# Default: none
# Default: 0
db = 0
# The username parameter is the user name used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
username =
# The password parameter is the password used to authenticate to Redis (see: https://redis.io/commands/auth).
# Default: none
password =
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment