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 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

rc-0.3.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

rc-0.3-py2-none-any.whl (15.4 kB view details)

Uploaded Python 2

File details

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

File metadata

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

File hashes

Hashes for rc-0.3.tar.gz
Algorithm Hash digest
SHA256 7982b0ce2aed7797ebfb4d2529af74b28c41031a7e7a7fe98a053b5066c2e2ac
MD5 800014c3ed225209352985d23a6fb7be
BLAKE2b-256 8f530a7e2773dc94172213a6592d48216c504037c51d95ecbf0f23b6feceb499

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for rc-0.3-py2-none-any.whl
Algorithm Hash digest
SHA256 53c30e52c4a122a978a2255a95c7af6952a478479f9c0fd65d6fc8bc15d72158
MD5 f314bc099583204564998944bdb519bd
BLAKE2b-256 ba88e6eafb615b3692c1e242ba5c947a7da790babf70fc7284b8f5bfc1b66b82

See more details on using hashes here.

Supported by

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