Skip to main content

Redis built into a python package

Project description

https://img.shields.io/travis/yahoo/redislite.svg https://img.shields.io/coveralls/yahoo/redislite.svg https://img.shields.io/pypi/dm/redislite.svg https://img.shields.io/pypi/v/redislite.svg https://img.shields.io/badge/python-2.7,3.4,pypy-blue.svg https://img.shields.io/pypi/l/redislite.svg
Documentation Status IRC Yahoo Group pythonredislite

Description

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

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

Requirements

The redislite module requires Python 2.7 or higher.

Installing on Linux

Make sure Python development headers are available when installing redislite.

On Ubuntu/Debian systems, install them with:

apt-get install python-dev

On Redhat/Fedora systems, install them with:

yum install python-devel

Installing on Mac OSX

Redislite for OSX comes as a wheel package by default that can be installed using current versions of pip.

To install Redislite on MacOSX using the sdist package instead you will need the XCode command line utilities installed. If you do not have xcode installed on recent OSX releases they can be installed by running:

xcode-select --install

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 = redislite.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 rdb 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']

Finally it’s possible ot spin up multiple instances with different configuration values for the Redis server. Here is an example that sets up 2 redis instances. One instance is configured to listen on port 8002, the second instance is a read-only slave of the first instance.

Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redislite
>>> master=redislite.Redis(serverconfig={'port': '8002'})
>>> slave=redislite.Redis(serverconfig={'slaveof': "127.0.0.1 8002"})
>>> slave.keys()
[]
>>> master.set('key', 'value')
True
>>> master.keys()
['key']
>>> slave.keys()
['key']
>>>

More Information

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

Redislite is Free software under the New BSD license, see LICENSE.txt for details.

Download files

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

Source Distribution

redislite-3.0.296.tar.gz (1.7 MB view details)

Uploaded Source

Built Distributions

redislite-3.0.296-cp35-cp35m-macosx_10_6_intel.whl (959.3 kB view details)

Uploaded CPython 3.5m macOS 10.6+ intel

redislite-3.0.296-cp34-cp34m-macosx_10_6_intel.whl (959.2 kB view details)

Uploaded CPython 3.4m macOS 10.6+ intel

redislite-3.0.296-cp27-none-macosx_10_6_intel.whl (959.2 kB view details)

Uploaded CPython 2.7 macOS 10.6+ intel

File details

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

File metadata

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

File hashes

Hashes for redislite-3.0.296.tar.gz
Algorithm Hash digest
SHA256 95347f4d50af3c4ff19a01c5779915890b0934a8d28a7e038ef0f76e406beef2
MD5 359ad42d38fafbf7cd9684d66ad114fc
BLAKE2b-256 6a889e51c7b7b2891952b2c79215a5e0ab16df7407c02e8708c39f010a1cda4d

See more details on using hashes here.

File details

Details for the file redislite-3.0.296-cp35-cp35m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for redislite-3.0.296-cp35-cp35m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 87fffb7cb2d11946b1bf6787763e560ee4d03c41e392567233e75c48cc92f88f
MD5 408c53e852443d082aa652657a127350
BLAKE2b-256 a52d505320c094c9070a7bbc01ec1d66f39623b106b3638c7874aa5a75576462

See more details on using hashes here.

File details

Details for the file redislite-3.0.296-cp34-cp34m-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for redislite-3.0.296-cp34-cp34m-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 23005f39168c3eaf5bd1fb10f9ffd6441afecef9c3401c64e8c56a3c7fab35d6
MD5 91d2427d82cfd141fbe2cc824fd3a0f4
BLAKE2b-256 9084b46c388cd6fca7ba76b6b99f7219d71144cdcaae233e253a85286669dc59

See more details on using hashes here.

File details

Details for the file redislite-3.0.296-cp27-none-macosx_10_6_intel.whl.

File metadata

File hashes

Hashes for redislite-3.0.296-cp27-none-macosx_10_6_intel.whl
Algorithm Hash digest
SHA256 849693ade065babba2bfe037b6d19d906ff9013cd0b50a19c2abbb60056cc85b
MD5 107e6887df6512660d6578b884739b1b
BLAKE2b-256 9ebae9b743b35ce16ef3ce2f58bf8f467c228651db4becf895b61d1015512437

See more details on using hashes here.

Supported by

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