From d87f1ddacc6b5d358c3583c09ecc81470fa9a7e8 Mon Sep 17 00:00:00 2001 From: gengchc2 Date: Thu, 12 Oct 2017 19:29:51 -0700 Subject: [PATCH] Add dbid parameter to pools's uri based on redis Now based on redis stored message store, zaqar can only write data into dbid = 0 database, it is not very convenient. Redis database has default 16 dbid database instances. In the redis pool's uri,we add dbid configuration parameters, if not dbid Parameter, the default dbid = 0. Change-Id: I6ba7b7ea0b0396ef56c920c1610552ece9779674 --- zaqar/storage/redis/driver.py | 3 +++ zaqar/storage/redis/options.py | 9 ++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/zaqar/storage/redis/driver.py b/zaqar/storage/redis/driver.py index a94231197..09641831c 100644 --- a/zaqar/storage/redis/driver.py +++ b/zaqar/storage/redis/driver.py @@ -27,6 +27,7 @@ from zaqar.storage.redis import options REDIS_DEFAULT_PORT = 6379 SENTINEL_DEFAULT_PORT = 26379 DEFAULT_SOCKET_TIMEOUT = 0.1 +DEFAULT_DBID = 0 STRATEGY_TCP = 1 STRATEGY_UNIX = 2 @@ -59,6 +60,7 @@ class ConnectionURI(object): self.strategy = None self.socket_timeout = float(query_params.get('socket_timeout', DEFAULT_SOCKET_TIMEOUT)) + self.dbid = int(query_params.get('dbid', DEFAULT_DBID)) # TCP self.port = None @@ -285,6 +287,7 @@ def _get_redis_client(driver): return redis.StrictRedis( host=connection_uri.hostname, port=connection_uri.port, + db=connection_uri.dbid, socket_timeout=connection_uri.socket_timeout) else: return redis.StrictRedis( diff --git a/zaqar/storage/redis/options.py b/zaqar/storage/redis/options.py index fff990807..3e4c42ccb 100644 --- a/zaqar/storage/redis/options.py +++ b/zaqar/storage/redis/options.py @@ -41,7 +41,14 @@ _COMMON_REDIS_OPTIONS = ( 'forms, the "socket_timeout" option may be ' 'specified in the query string. Its value is ' 'given in seconds. If not provided, ' - '"socket_timeout" defaults to 0.1 seconds.')), + '"socket_timeout" defaults to 0.1 seconds.' + 'There are multiple database instances in redis ' + 'database, for example in the /etc/redis/redis.conf, ' + 'if the parameter is "database 16", there are 16 ' + 'database instances. By default, the data is stored ' + 'in db = 0 database, if you want to use db = 1 ' + 'database, you can use the following form: ' + '"redis://host[:port][?dbid=1]".')), cfg.IntOpt('max_reconnect_attempts', default=10, deprecated_opts=[cfg.DeprecatedOpt(