def _get_count(store: typing.Callable, search_key: str) -> int: """Wraps redis.mget command. """ CHUNK_SIZE = 5000 _, keys = store.scan(match=search_key, count=CHUNK_SIZE) return len(keys)
def _get_all(store: typing.Callable, search_key: str) -> typing.List[typing.Any]: """Wraps redis.mget command. """ CHUNK_SIZE = 5000 _, keys = store.scan(match=search_key, count=CHUNK_SIZE) return [_decode_item(i) for i in store.mget(keys)] if keys else []
def _flush(store: typing.Callable, ns_keys: str): """Flushes data from cache. """ CHUNK_SIZE = 1000 cursor = '0' while cursor != 0: cursor, keys = store.scan(cursor=cursor, match=ns_keys, count=CHUNK_SIZE) if keys: store.delete(*keys)
def _delete_many(store: typing.Callable, search_key: SearchKey): """Deletes items under matching keys. """ chunk_size = 1000 cursor = '0' while cursor != 0: cursor, keys = store.scan(cursor=cursor, match=search_key.key, count=chunk_size) if keys: store.delete(*keys)
def _get_one_from_many(store: typing.Callable, item_key: ItemKey) -> typing.Any: """Returns item under first matched key. """ chunk_size = 1000 cursor = '0' while cursor != 0: cursor, keys = store.scan(cursor=cursor, match=item_key.key, count=chunk_size) if keys: return _decode_item(store.get(keys[0]))
def _get_count(store: typing.Callable, search_key: SearchKey) -> int: """Returns length of collection under matched keys. """ count = 0 chunk_size = 1000 cursor = '0' while cursor != 0: cursor, keys = store.scan(cursor=cursor, match=search_key.key, count=chunk_size) count += len(keys) return count
def _get_many(store: typing.Callable, search_key: SearchKey) -> typing.List[typing.Any]: """Returns collection cached under all matched keys. """ keys = [] chunk_size = 2000 cursor = '0' while cursor != 0: cursor, keys_ = store.scan(cursor=cursor, match=search_key.key, count=chunk_size) keys += keys_ return [_decode_item(i) for i in store.mget(keys)] if keys else []
def _get_counter_many( store: typing.Callable, search_key: SearchKey ) -> typing.Tuple[typing.List[str], typing.List[int]]: """Returns counts under matched keys. """ keys = [] chunk_size = 1000 cursor = '0' while cursor != 0: cursor, keys_ = store.scan(cursor=cursor, match=search_key.key, count=chunk_size) keys += keys_ return [i.decode('utf8') for i in keys], [int(i) for i in store.mget(keys)]