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 welcome.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rc-0.3.1.tar.gz.
File metadata
- Download URL: rc-0.3.1.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd45ca7c37f383aba3cdf7fccf5fff0f5b6eacb70d7ca75532ac9410be2a0151
|
|
| MD5 |
d390978589d402330d7cb813d997ccf2
|
|
| BLAKE2b-256 |
395d82bce78023c470345d27b61cb3f1bc4fdc8249dcd7d83bc05b1319687adf
|
File details
Details for the file rc-0.3.1-py2-none-any.whl.
File metadata
- Download URL: rc-0.3.1-py2-none-any.whl
- Upload date:
- Size: 15.4 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6446eac03afd75e6198d6a4e1acd4f569d914a2cc908bdb849f022a3e346fa0
|
|
| MD5 |
3e6ec37bda425e9233be831eeeebd3e5
|
|
| BLAKE2b-256 |
6c0f70df511b9ee2ac982ef1a4d422b0a6c2391fda1d9de4cd038f3f2e69a43f
|