Redis built into a python package
Project description
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.
Requirements
The redislite module requires Python 2.7 or higher.
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
On Mac OSX you may 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
Note redislite and its dependencies use the gcc compiler. On OSX you may run into errors indicating that your machine is using clang to compile instead, for example:
clang: error: unknown argument: '-mno-fused-madd' [-Wunused-command-line-argument-hard-error-in-future]
If this is the case, set your environment variable to override the use of clang in favor of gcc:
CC=gcc
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 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file redislite-1.0.243.tar.gz
.
File metadata
- Download URL: redislite-1.0.243.tar.gz
- Upload date:
- Size: 4.0 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a78e34faa3095f5e48913d6cbc7797493129da180d47bdd563ae6a184b263016 |
|
MD5 | 036e5e126bc5f650889ef9d525538d85 |
|
BLAKE2b-256 | 6b53ccc7fae155d96d7ec3452d52d9fc29eecf79e22161fd830c42e5507eecda |
File details
Details for the file redislite-1.0.243-cp27-none-macosx_10_6_intel.whl
.
File metadata
- Download URL: redislite-1.0.243-cp27-none-macosx_10_6_intel.whl
- Upload date:
- Size: 859.9 kB
- Tags: CPython 2.7, macOS 10.6+ intel
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ba11d4cf15987d6ed0babc104c94351abf5a5e3c870087e3d44458e0de65fd32 |
|
MD5 | 78dc53697599b5665084a2bb1fb084d0 |
|
BLAKE2b-256 | abe5d359bd1f88be70c6c559eb39fe23bd178ea1147a8e868a52ebcbe80916b0 |