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
This commit is contained in:
gengchc2 2017-10-12 19:29:51 -07:00
parent 5ff2d1a9be
commit d87f1ddacc
2 changed files with 11 additions and 1 deletions

View File

@ -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(

View File

@ -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(