Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lamenezes/redistore
Pythonic interface for redis
https://github.com/lamenezes/redistore
Last synced: 6 days ago
JSON representation
Pythonic interface for redis
- Host: GitHub
- URL: https://github.com/lamenezes/redistore
- Owner: lamenezes
- License: mit
- Created: 2018-03-24T22:06:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-07-22T16:11:07.000Z (over 6 years ago)
- Last Synced: 2024-09-22T16:07:13.908Z (about 1 month ago)
- Language: Python
- Size: 18.6 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
- starred-awesome - redistore - Pythonic interface for redis (Python)
README
=========
redistore
=========.. image:: https://badge.fury.io/py/redistore.svg
:target: https://badge.fury.io/py/redistore.. image:: https://travis-ci.org/lamenezes/redistore.svg?branch=master
:target: https://travis-ci.org/lamenezes/redistore.. image:: https://coveralls.io/repos/github/lamenezes/redistore/badge.svg?branch=master
:target: https://coveralls.io/github/lamenezes/redistore?branch=master.. image:: https://img.shields.io/badge/python-3.4,3.5,3.6-blue.svg
:target: https://github.com/lamenezes/simple-modelSimple python interface for redis
Installation
============.. code:: bash
$ pip install redistore
Usage
=====.. code:: python
>>> 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:
.. code:: python
>>> store['foo'] = 'bar'
>>> store['foo']
'bar'
>>> 'foo' in store
True
>>> del store['foo']
>>> store['foo']
...
KeyError: 'foo'Or using methods:
.. code:: python
>>> store.set('baz', 'qux')
>>> store.get('baz')
'qux'``redistore`` support other data types, e.g., hashes. they are used exactly like a dict:
.. code:: python
>>> 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'