rc, the redis cache
Project description
rc - the redis cache.
easy to use
can build cache cluster
batch-fetch multiple cache results (do it in parallel for cluster)
For full documentation see rc.readthedocs.org.
Installation
$ pip install rc
Quickstart
A minimal cache example looks like this:
from rc import Cache
cache = Cache()
assert cache.set('key', 'value')
assert cache.get('key') == 'value'
assert cache.get('foo') is None
assert cache.set('list', [1])
assert cache.get('list') == [1]
A cache cluster use a redis cluster as backend:
from rc import CacheCluster
cache = CacheCluster({
'cache01': {'host': 'redis-host01'},
'cache02': {'host': 'redis-host02'},
'cache03': {'host': 'redis-host03'},
'cache04': {'host': 'redis-host04', 'db': 1},
})
Cache decorator:
@cache.cache()
def load(name, offset):
return load_from_database(name, offset)
rv = load('name', offset=10)
Batch fetch multiple cache results:
assert cache.get_many('key', 'foo') == ['value', None]
# for cache decorated function
@cache.cache()
def cached_func(param):
return param
results = []
# with the context manager, the function
# is executed and return a promise
with cache.batch_mode():
for i in range(10):
results.append(cached_func(i))
for i, rv in enumerate(results):
assert rv.value == i
Cache invalidation:
cache.delete('key')
# for decorated function
cache.invalidate(load, 'name', offset=10)
Better
If you feel anything wrong, feedbacks or pull requests are welcomed.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rc-0.1.1.tar.gz
(11.6 kB
view details)
Built Distribution
rc-0.1.1-py2-none-any.whl
(14.9 kB
view details)
File details
Details for the file rc-0.1.1.tar.gz
.
File metadata
- Download URL: rc-0.1.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d4dd69bffe1978866847fdd77ca31d6c91d173c2094ef706ce17ce10ad2b0e33 |
|
MD5 | 8a7310b1739927685191aa82b0997588 |
|
BLAKE2b-256 | ea2dfe960b49c40e23f5424869d90181b88b1805dc038d5bf93c94de1f3bf9a8 |
File details
Details for the file rc-0.1.1-py2-none-any.whl
.
File metadata
- Download URL: rc-0.1.1-py2-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af8e8ea1880b29b3e288fa87639a2d3f38ad9f73e7bc6ffe8f46b72564471040 |
|
MD5 | 3694539014afbaadfaba30c4513be0e6 |
|
BLAKE2b-256 | 818ebd1125789a41e0226ac6c83c0bb3b06b323e18586192ef774fff38ae909b |