Skip to main content

Redis built into a python package

Project description

https://travis-ci.org/yahoo/redislite.svg?branch=master https://coveralls.io/repos/yahoo/redislite/badge.svg https://pypip.in/download/redislite/badge.svg https://pypip.in/version/redislite/badge.svg https://pypip.in/py_versions/redislite/badge.svg https://pypip.in/license/redislite/badge.svg Documentation Status

Description

Self contained Python interface to the Redis key-value store.

It makes it possible to use redis without the need to install and configure a redis server.

Installation

To install redislite, simply:

$ pip install redislite

or using easy_install:

$ easy_install redislite

or from source:

$ python setup.py install

Getting Started

>>> import redislite
>>> r = redis.StrictRedis()
>>> r.set('foo', 'bar')
True
>>> r.get('foo')
'bar'

Usage

redislite provides enhanced versions of the redis.Redis() and redis.StrictRedis() classes that take the same arguments as the corresponding redis classes and take one additional optional argument. Which is the name of the redis rbd file to use. If the argument is not provided it will create a new one.

redislite also provides functions to MonkeyPatch the redis.Redis and redis.StrictRedis classes to use redislite, so existing python code that uses redis can use the redislite version.

Example

Here we open a Python shell and set a key in our embedded redis db

>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
[]
>>> redis_connection.set('key', 'value')
True
>>> redis_connection.get('key')
'value'

Here we open the same redis db and access the key we created during the last run

>>> from redislite import Redis
>>> redis_connection = Redis('/tmp/redis.db')
>>> redis_connection.keys()
['key']
>>> redis_connection.get('key')
'value'

It’s also possible to MonkeyPatch the normal redis classes to allow modules that use redis to use the redislite classes. Here we patch redis and use the redis_collections module.

>>> import redislite.patch
>>> redislite.patch.patch_redis()
>>> import redis_collections
>>> td = redis_collections.Dict()
>>> td['foo']='bar'
>>> td.keys()
['foo']

Or the Walrus module

>>> from redislite.patch import patch_redis
>>> patch_redis('/tmp/walrus.db')
>>> from walrus import *
>>> db = Database()
>>> huey = db.Hash('huey')
>>> huey.update(color='white', temperament='ornery', type='kitty')
<Hash "huey": {'color': 'white', 'type': 'kitty', 'temperament': 'ornery'}>
>>> huey.keys()
['color', 'type', 'temperament']
>>> 'color' in huey
True
>>> huey['color']
'white'

More Information

There is more detailed information on the redislite documentation page at http://redislite.readthedocs.org/en/latest/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

redislite-1.0.63.tar.gz (3.6 MB view details)

Uploaded Source

File details

Details for the file redislite-1.0.63.tar.gz.

File metadata

  • Download URL: redislite-1.0.63.tar.gz
  • Upload date:
  • Size: 3.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for redislite-1.0.63.tar.gz
Algorithm Hash digest
SHA256 54511f8ca9ae9687d8c71963270bcec2a257e91de9720179bbb04e8489044225
MD5 b28546b0b89cabefad3d07dcb6ba4bd7
BLAKE2b-256 40712b2f23d01e22153a5c227e8d80393123cdbcf4d782f9ac5850ba12de229f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page