Exemple #1
0
def _set_one_singleton(store: typing.Callable,
                       item: Item) -> typing.Tuple[str, bool]:
    """Sets item under a key if not already cached.
    
    """
    key, was_cached = item.key, bool(store.setnx(item.key, item.data_as_json))
    if was_cached and item.expiration:
        store.expire(key, item.expiration)

    return key, was_cached
Exemple #2
0
def _setnx(store: typing.Callable, key: str, data: typing.Any) -> typing.Tuple[str, bool]:
    """Wraps redis.setnx command.
    
    """
    return bool(store.setnx(key, json.dumps(encoder.encode(data), indent=4)))