Skip to content

CompileInc/redis-collections

Repository files navigation

Redis Collections

https://travis-ci.org/honzajavorek/redis-collections.svg?branch=masterhttps://coveralls.io/repos/github/honzajavorek/redis-collections/badge.svg?branch=master

redis-collections is a Python library that provides a high-level interface to Redis, the excellent key-value store.

Quickstart

Install the library with pip install redis-collections. Import the collections from the top-level redis_collections package.

Standard collections

The standard collections (e.g. Dict, List, Set) behave like their Python counterparts:

>>>fromredis_collectionsimportDict, List, Set>>>D=Dict() >>>D['answer'] =42>>>D['answer'] 42
CollectionRedis typeDescription
DictHashEmulates Python's dict
ListListEmulates Python's list
SetSetEmulates Python's set
CounterHashEmulates Python's collections.Counter
DefaultDictHashEmulates Python's collections.defaultdict
DequeListEmulates Python's collections.deque

Syncable collections

The syncable collections in this package provide types whose contents are kept in memory. When their sync method is called those contents are written to Redis:

>>>fromredis_collectionsimportSyncableDict>>>withSyncableDict() asD: ... D['a'] =1# No write to Redis ... D['a'] +=1# No read from or write to Redis>>>D['a'] # D.sync() is called at the end of the with block2
CollectionPython typeDescription
SyncableDictdictSyncs to a Redis Hash
SyncableListlistSyncs to a Redis List
SyncableSetsetSyncs to a Redis Set
SyncableCountercollections.CounterSyncs to a Redis Hash
SyncableDequecollections.dequeSyncs to a Redis List
SyncableDefaultDictcollections.defaultdictSyncs to a Redis Hash

Other collections

The LRUDict collection stores recently used items in in memory. It pushes older items to Redis:

>>>fromredis_collectionsimportLRUDict>>>D=LRUDict(maxsize=2) >>>D['a'] =1>>>D['b'] =2>>>D['c'] =2# 'a' is pushed to Redis and 'c' is stored locally>>>D['a'] # 'b' is pushed to Redis and 'a' is retrieved for local storage1>>>D.sync() # All items are copied to Redis

The SortedSetCounter provides access to the Redis Sorted Set type:

>>>fromredis_collectionsimportSortedSetCounter>>>ssc=SortedSetCounter([('earth', 300), ('mercury', 100)]) >>>ssc.set_score('venus', 200) >>>ssc.get_score('venus') 200.0>>>ssc.items() [('mercury', 100.0), ('venus', 200.0), ('earth', 300.0)]

Documentation

For more information, see redis-collections.readthedocs.io

Maintainers

License: ISC

© 2013-? Honza Javorek <mail@honzajavorek>

This work is licensed under ISC license.

About

Set of basic Python collections backed by Redis

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python100.0%