Skip to content
Snippets Groups Projects
Commit bcd7d179 authored by Erik Reid's avatar Erik Reid
Browse files

rough draft current/next selection

parent cf88fec8
No related branches found
No related tags found
No related merge requests found
import logging
import redis import redis
import redis.sentinel import redis.sentinel
logger = logging.getLogger(__name__)
def _get_redis(config, dbid=None):
if 'sentinel' in config:
_params = config['sentinel']
else:
_params = config['redis']
if dbid is None:
dbid = min(_params['databases'])
assert dbid in _params['databases']
kwargs = {
'db': dbid,
'socket_timeout': 0.1
}
def get_redis(config):
if 'sentinel' in config: if 'sentinel' in config:
sentinel = redis.sentinel.Sentinel([( sentinel = redis.sentinel.Sentinel([(
config['sentinel']['hostname'], config['sentinel']['hostname'],
config['sentinel']['port'])], config['sentinel']['port'])],
socket_timeout=0.1) **kwargs)
return sentinel.master_for( return dbid, sentinel.master_for(
config['sentinel']['name'], config['sentinel']['name'],
socket_timeout=0.1) socket_timeout=0.1)
else: else:
return redis.StrictRedis( return dbid, redis.StrictRedis(
host=config['redis']['hostname'], host=config['redis']['hostname'],
port=config['redis']['port']) port=config['redis']['port'],
**kwargs)
def _get_specific_redis(config, db_id_key):
db, r = _get_redis(config)
required_db = r.get(db_id_key)
if required_db is None:
logger.warning('can''t determine current db, using: {}'.format(db))
return r
required_db = int(required_db.decode('utf-8'))
if db == required_db:
return r
db, r = _get_redis(config, required_db)
assert db == required_db
return r
def get_current_redis(config):
return _get_specific_redis(config, 'db:current')
def get_next_redis(config):
return _get_specific_redis(config, 'db:current')
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