Skip to content
Snippets Groups Projects
common.py 493 B
Newer Older
import redis
import redis.sentinel


def get_redis(config):
    if 'sentinel' in config:
        sentinel = redis.sentinel.Sentinel([(
            config['sentinel']['hostname'],
            config['sentinel']['port'])],
            socket_timeout=0.1)
        return sentinel.master_for(
            config['sentinel']['name'],
            socket_timeout=0.1)
    else:
        return redis.StrictRedis(
            host=config['redis']['hostname'],
            port=config['redis']['port'])