Пример #1
0
    def test_redis_cache_forever_tags_can_be_flushed(self):
        store = flexmock(RedisStore(redis_class=FakeStrictRedis))
        tag_set = flexmock(TagSet(store, ['foo', 'bar']))

        tag_set.should_receive('get_namespace').and_return('foo|bar')
        redis = RedisTaggedCache(store, tag_set)

        store.should_receive('get_prefix').and_return('prefix:')
        conn = flexmock()
        store.should_receive('connection').and_return(conn)

        conn.should_receive('lrange').once()\
            .with_args('prefix:foo:forever', 0, -1)\
            .and_return(['key1', 'key2'])
        conn.should_receive('lrange').once()\
            .with_args('prefix:bar:forever', 0, -1)\
            .and_return(['key3'])

        conn.should_receive('delete').once().with_args('key1', 'key2')
        conn.should_receive('delete').once().with_args('key3')
        conn.should_receive('delete').once().with_args('prefix:foo:forever')
        conn.should_receive('delete').once().with_args('prefix:bar:forever')

        tag_set.should_receive('reset').once()

        redis.flush()
Пример #2
0
    def test_redis_cache_tags_push_forever_keys_correctly(self):
        store = flexmock(RedisStore(redis_class=FakeStrictRedis))
        tag_set = flexmock(TagSet(store, ['foo', 'bar']))

        tag_set.should_receive('get_namespace').and_return('foo|bar')
        redis = RedisTaggedCache(store, tag_set)

        store.should_receive('get_prefix').and_return('prefix:')
        conn = flexmock()
        store.should_receive('connection').and_return(conn)
        conn.should_receive('lpush').once()\
            .with_args('prefix:foo:forever', 'prefix:%s:key1' % hashlib.sha1(b'foo|bar').hexdigest())
        conn.should_receive('lpush').once()\
            .with_args('prefix:bar:forever', 'prefix:%s:key1' % hashlib.sha1(b'foo|bar').hexdigest())

        store.should_receive('forever').with_args(hashlib.sha1(b'foo|bar').hexdigest() + ':key1', 'key1:value')

        redis.forever('key1', 'key1:value')