Skip to main content

rc, the redis cache

Project description

rc: the redis cache

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.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

rc-0.1-py2-none-any.whl (14.8 kB view details)

Uploaded Python 2

File details

Details for the file rc-0.1.tar.gz.

File metadata

  • Download URL: rc-0.1.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rc-0.1.tar.gz
Algorithm Hash digest
SHA256 5d2f50d59e87dfa5ecc031e2cd4c6b03e2eb89aa5b056f7c6667404616b4e039
MD5 fee43d434cfa54bca14b168e7ee063a7
BLAKE2b-256 714e0ee4117662d00c4d371ad0adf4d625eacf3bb689104415d6b791f48e50c4

See more details on using hashes here.

File details

Details for the file rc-0.1-py2-none-any.whl.

File metadata

  • Download URL: rc-0.1-py2-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 2
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for rc-0.1-py2-none-any.whl
Algorithm Hash digest
SHA256 dbeeb43528ec8649331b072df7f7d0f6f48298d1e1401d87aa07d96e35ba9afd
MD5 29fe3f16c43273e34542206b9bc5ce74
BLAKE2b-256 0ac13f6445d199d5de30771560933bc23440b34e03fd7b097c90571e8062d77d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page