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

Uploaded Source

Built Distribution

rc-0.2.1-py2-none-any.whl (15.3 kB view details)

Uploaded Python 2

File details

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

File metadata

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

File hashes

Hashes for rc-0.2.1.tar.gz
Algorithm Hash digest
SHA256 659ab634428b36556fa5fd2aeb6cb1e9df32852b160b5bcc9f524341f3bbfebc
MD5 dfe683e6036a62687b5f00214cdc7d63
BLAKE2b-256 e7c6f2ad26d6829682376f387282df78996e19ad1daccfba17eb6f72054d81a5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for rc-0.2.1-py2-none-any.whl
Algorithm Hash digest
SHA256 afa0817bf2cfd60fecb185a4e4fb084c3a8913ede3266da2cf33731b19149090
MD5 18363098172f8bc97c8933e99d05031c
BLAKE2b-256 a87106f62801b3cfbd9becccb0944cddb62d51c492552c0fd81a6fe56658de26

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