redistore

Simple python interface for redis


License
MIT
Install
pip install redistore==0.1.0

Documentation

redistore

https://travis-ci.org/lamenezes/redistore.svg?branch=master https://coveralls.io/repos/github/lamenezes/redistore/badge.svg?branch=master

Simple python interface for redis

Installation

$ pip install redistore

Usage

>>> import redistore
>>> store = redistore.get(host='localhost', port=6379, db=0)

Now you can access and store keys and values with a dict-like interface:

>>> store['foo'] = 'bar'
>>> store['foo']
'bar'
>>> 'foo' in store
True
>>> del store['foo']
>>> store['foo']
...
KeyError: 'foo'

Or using methods:

>>> store.set('baz', 'qux')
>>> store.get('baz')
'qux'

redistore support other data types, e.g., hashes. they are used exactly like a dict:

>>> store['hash'] = {}  # creates a hash without any values
>>> store['hash']['my'] = 'hash'
>>> 'my' in store['hash']
True
>>> store['hash']['my']
'hash'
>>> store['hash'].update({'baz': 'qux'})
>>> store['hash']['baz']
'qux'
>>> len(store['hash'])
2
>>> list(store.keys())
['foo', 'bar']
>>> for key, value in store.items():
...    print(key, value)
...
my hash
baz qux
>>> store['other_hash'] = {'foo': 'bar'}  # creates a hash with values
>>> store['other_hash']['foo']
'bar'