Example #1
0
def init():
    global redis_conn, cache_prefix
    cfg = config.load()
    cache = cfg.cache
    if not cache:
        return

    logging.info('Enabling storage cache on Redis')
    if not isinstance(cache, dict):
        cache = {}
    for k, v in cache.iteritems():
        redis_opts[k] = v
    logging.info('Redis config: {0}'.format(redis_opts))
    redis_conn = redis.StrictRedis(host=redis_opts['host'],
                                   port=int(redis_opts['port']),
                                   db=int(redis_opts['db']),
                                   password=redis_opts['password'])
    cache_prefix = 'cache_path:{0}'.format(cfg.get('storage_path', '/'))

    # Enable the LRU as well
    lru.init(
        host=redis_opts['host'],
        port=int(redis_opts['port']),
        db=int(redis_opts['db']),
        password=redis_opts['password'],
        path=cfg.get('storage_path', '/')
    )
Example #2
0
def init():
    global redis_conn, cache_prefix
    cfg = config.load()
    cache = cfg.cache
    if not cache:
        return

    logging.info('Enabling storage cache on Redis')
    if not isinstance(cache, dict):
        cache = {}
    for k, v in cache.iteritems():
        redis_opts[k] = v
    logging.info('Redis config: {0}'.format(redis_opts))
    redis_conn = redis.StrictRedis(host=redis_opts['host'],
                                   port=int(redis_opts['port']),
                                   db=int(redis_opts['db']),
                                   password=redis_opts['password'])
    cache_prefix = 'cache_path:{0}'.format(cfg.get('storage_path', '/'))

    # Enable the LRU as well
    lru.init(host=redis_opts['host'],
             port=int(redis_opts['port']),
             db=int(redis_opts['db']),
             password=redis_opts['password'],
             path=cfg.get('storage_path', '/'))
Example #3
0
def enable_redis_lru(cache, path):
    if not cache or not cache.host:
        logger.warn('LRU cache disabled!')
        return
    logger.info('Enabling lru cache on Redis')
    logger.info('Redis lru config: {0}'.format(cache))
    lru.init(host=cache.host,
             port=cache.port,
             db=cache.db,
             password=cache.password,
             path=path or '/')
Example #4
0
def enable_redis_lru(cache, path):
    if not cache or not cache.host:
        logger.warn('LRU cache disabled!')
        return
    logger.info('Enabling lru cache on Redis')
    logger.info('Redis lru config: {0}'.format(cache))
    lru.init(
        host=cache.host,
        port=cache.port,
        db=cache.db,
        password=cache.password,
        path=path or '/'
    )
Example #5
0
def enable_redis_lru(cfg):
    cache = cfg.cache_lru
    if not cache:
        return
    logging.info('Enabling lru cache on Redis')
    if not isinstance(cache, dict):
        cache = {}
    redis_opts = {
        'host': 'localhost',
        'port': 6379,
        'db': 0,
        'password': None
    }
    for k, v in cache.iteritems():
        redis_opts[k] = v

    logging.info('Redis lru config: {0}'.format(redis_opts))
    lru.init(
        host=redis_opts['host'],
        port=int(redis_opts['port']),
        db=int(redis_opts['db']),
        password=redis_opts['password'],
        path=cfg.get('storage_path', '/')
    )
Example #6
0
# limitations under the License.

from docker_registry.core import compat
from docker_registry.core import lru

# In case you want to mock (and that doesn't work well)
# import mock
# import mockredis
# @mock.patch('docker_registry.core.lru.redis.StrictRedis',
#             mockredis.mock_strict_redis_client)
# def boot():
#     lru.init()

# boot()

lru.init()


class Dumb(object):

    value = {}

    @lru.get
    def get(self, key):
        if key not in self.value:
            return None
        return self.value[key]

    @lru.set
    def set(self, key, value):
        self.value[key] = value
 def setUp(self):
     lru.init()
     self._dumb = Dumb()
Example #8
0
# limitations under the License.

from docker_registry.core import compat
from docker_registry.core import lru

# In case you want to mock (and that doesn't work well)
# import mock
# import mockredis
# @mock.patch('docker_registry.core.lru.redis.StrictRedis',
#             mockredis.mock_strict_redis_client)
# def boot():
#     lru.init()

# boot()

lru.init()


class Dumb(object):

    value = {}

    @lru.get
    def get(self, key):
        if key not in self.value:
            return None
        return self.value[key]

    @lru.set
    def set(self, key, value):
        self.value[key] = value