Redis is an in-memory data store with on-disk persistence. It offers a high-performace cache that scales exceptionally well, making it an ideal choice for larger applications.
Redis operates on data in memory, and by default also persists data to snapshots on disk. This is optimized for performance with a minor risk of data loss, which is usually the best configuration for a cache. If you need different behavior, the frequency and type of persistence can be customized or disabled entirely. See Redis Persistence for details.
>>> session = CachedSession('http_cache', backend='redis', host='192.168.1.63', port=6379)
>>> backend = RedisCache(host='192.168.1.63', port=6379) >>> session = CachedSession('http_cache', backend=backend)
- class requests_cache.backends.redis.RedisCache(namespace='http_cache', connection=None, **kwargs)¶
Redis cache backend
Remove multiple responses and their associated redirects from the cache
Delete all items from the cache
- create_key(request=None, **kwargs)¶
Create a normalized cache key from a request object
Delete a response or redirect from the cache, as well any associated redirect history
- delete_url(url, method='GET', **kwargs)¶
Delete a cached response for the specified request
- delete_urls(urls, method='GET', **kwargs)¶
Delete all cached responses for the specified requests
- get_response(key, default=None)¶
Retrieve a response from the cache, if it exists
- has_url(url, method='GET', **kwargs)¶
Trueif the specified request is cached
Get all cache keys for redirects and valid responses combined
Remove expired and invalid responses from the cache, optionally with revalidation
Get the number of responses in the cache, excluding invalid (unusable) responses. Can also optionally exclude expired responses.
- Return type
- save_response(response, cache_key=None, expires=None)¶
Save a response to the cache
- class requests_cache.backends.redis.RedisDict(namespace, collection_name='http_cache', connection=None, **kwargs)¶
A dictionary-like interface for Redis operations
In order to deal with how Redis stores data, all keys will be encoded and all values will be serialized.
The full hash name will be
Delete multiple keys from the cache. Does not raise errors for missing keys.
- clear() None. Remove all items from D. ¶
- get(k[, d]) D[k] if k in D, else d. d defaults to None. ¶
- items() a set-like object providing a view on D’s items ¶
- keys() a set-like object providing a view on D’s keys ¶
- pop(k[, d]) v, remove specified key and return the corresponding value. ¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair ¶
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D ¶
- update([E, ]**F) None. Update D from mapping/iterable E and F. ¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D’s values ¶