2016-11-26 20:30:00 +01:00
|
|
|
import redis
|
2017-08-18 00:06:57 +02:00
|
|
|
from redis.exceptions import BusyLoadingError
|
|
|
|
from retry import retry
|
2016-11-26 20:30:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
class Redis:
|
2016-12-11 18:41:40 +01:00
|
|
|
"""
|
|
|
|
Small redis wrapper, to simplify work with connection pool
|
|
|
|
"""
|
2016-11-26 20:30:00 +01:00
|
|
|
def __init__(self, config):
|
|
|
|
self.pool = redis.ConnectionPool(host=config['redis']['host'],
|
2016-11-27 16:34:21 +01:00
|
|
|
port=config.getint('redis', 'port'),
|
2016-11-26 20:30:00 +01:00
|
|
|
db=config['redis']['db'])
|
2017-08-18 00:06:57 +02:00
|
|
|
self.__ensure_dataset_loaded()
|
2016-11-26 20:30:00 +01:00
|
|
|
|
|
|
|
def instance(self):
|
|
|
|
return redis.Redis(connection_pool=self.pool)
|
2017-08-18 00:06:57 +02:00
|
|
|
|
2017-08-19 17:28:37 +02:00
|
|
|
@retry(BusyLoadingError, tries=5, delay=10, logger=None)
|
2017-08-18 00:06:57 +02:00
|
|
|
def __ensure_dataset_loaded(self):
|
|
|
|
self.instance().ping()
|