• Stars
    star
    121
  • Rank 293,924 (Top 6 %)
  • Language
    Python
  • License
    Other
  • Created about 9 years ago
  • Updated over 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Redis cache cluster system in Python

rc

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.

More Repositories

1

plan

Crontab jobs management in Python
Python
1,171
star
2

color-thief-py

Grabs the dominant color or a representative color palette from an image. Uses Python and Pillow.
Python
1,017
star
3

pencil

A web application microframework for Rust
Rust
871
star
4

django-grpc-framework

gRPC for Django.
Python
382
star
5

python-snippets

A basket of python snippets
222
star
6

sender

One easy to use Python SMTP client
Python
197
star
7

easy-python

Libraries you didn't know you would need
192
star
8

knight

One HTTP development server with reloader for Go
Go
69
star
9

flask-snippets

Flask Snippets
Python
68
star
10

shortly

A URL shortener
Python
50
star
11

flask-profile

Flask Application Profiler
JavaScript
37
star
12

lookup

Look up words via the command line
Python
36
star
13

batpod

A really tiny web framework
Python
23
star
14

python

Python Style Guide
22
star
15

flask-application-wizard

Helper script to create Flask Applications
Python
16
star
16

cli

Rust command line utility
Rust
13
star
17

clock

A minimalist datetime library for Python
Python
10
star
18

pypages

Simple Python Pagination
Python
9
star
19

golang-tour

Sample Go code from the Tour of Go
4
star
20

slim

SimpleHTTPServer serving files relative to the current directory
Go
2
star
21

fengsp.github.io

Shipeng Feng's Writings
HTML
1
star
22

fork

Doing subprocess in Python should be easy
Python
1
star
23

douban-photoalbum-downloader

Download douban photo album
Python
1
star
24

blog

My personal website
HTML
1
star
25

faster-python

Write Faster Python Programs
Python
1
star
26

ninja

The ninja template engine for Go
Go
1
star
27

markdown-online

Put your local markdowns online
JavaScript
1
star
28

pyalgorithms

Algorithms in Python
Python
1
star
29

PyObject

Python 2.5 Source
Python
1
star