Skip to main content

Redis built into a python package

Project description

Redislite

Build Status Coverage Current Version Supported Python License Documentation

Description

Redislite is a self contained Python interface to the Redis key-value store.

It provides enhanced versions of the Redis-Py Python bindings for Redis. That provide the following added functionality:

  • Easy to use - It provides a built in Redis server that is automatically installed, configured and managed when the Redis bindings are used.
  • Flexible - Create a single server shared by multiple programs or multiple independent servers. All the servers provided by Redislite support all Redis functionality including advanced features such as replication and clustering.
  • Compatible - It provides enhanced versions of the Redis-Py python Redis bindings as well as functions to patch them to allow most existing code that uses them to run with little or no modifications.
  • Secure - It uses a secure default Redis configuraton that is only accessible by the creating user on the computer system it is run on.

Requirements

The redislite module requires Python 2.7 or higher.

Installing requirements 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 requirements 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

Installing requirements on Microsoft Windows

Redislite can be installed on newer releases of Windows 10 under the Bash on Ubuntu shell.

Install it using the instructions at https://msdn.microsoft.com/commandline/wsl/install_guide

Then start the bash shell and install the python-dev package as follows:

apt-get install python-dev

Installation

To install redislite, simply:

$ pip install redislite

or from source:

$ python setup.py install

Getting Started

redislite provides enhanced versions of the redis-py 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 set up a new redis server.

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.

Examples

Here are some examples of using the redislite module.

Setting a value

Here we open a Python shell and set a key in our embedded Redis db. Redislite will automatically start the Redis server when the Redis() object is created and shut it down cleanly when the Python interpreter exits.

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

Persistence

Now we open the same Redis db and access the key we created during the last run. Redislite will automatically start the Redis server using the same configuration as last time, so the value that was set in the previous example is still available.

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

Compatibility

It's 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']

Running and using Multiple servers

Redislite will start a new server if the redis rdb fileame isn't specified or is new. In this example we start 10 seperate redis servers and set the value of the key 'servernumber' to a different value in each server.

Then we access the value of 'servernumber' and print it.

>>> import redislite
>>> servers = {}
>>> for redis_server_number in range(10):
...     servers[redis_server_number] = redislite.Redis()
...     servers[redis_server_number].set('servernumber', redis_server_number)
...
True
True
True
True
True
True
True
True
True
True
>>> for redis_server in servers.values():
...     redis_server.get('servernumber')
...
b'0'
b'1'
b'2'
b'3'
b'4'
b'5'
b'6'
b'7'
b'8'
b'9'

Multiple Servers with different configurations in the same script

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

>>> 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


Download files

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

Source Distribution

redislite-5.0.121683.tar.gz (1.9 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

redislite-5.0.121683-cp37-cp37m-manylinux2010_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.7mmanylinux: glibc 2.12+ x86-64

redislite-5.0.121683-cp36-cp36m-manylinux2010_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.6mmanylinux: glibc 2.12+ x86-64

redislite-5.0.121683-cp35-cp35m-manylinux2010_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.5mmanylinux: glibc 2.12+ x86-64

redislite-5.0.121683-cp34-cp34m-manylinux2010_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.4mmanylinux: glibc 2.12+ x86-64

redislite-5.0.121683-cp27-cp27mu-manylinux2010_x86_64.whl (3.3 MB view details)

Uploaded CPython 2.7mumanylinux: glibc 2.12+ x86-64

redislite-5.0.121683-cp27-cp27m-manylinux2010_x86_64.whl (3.3 MB view details)

Uploaded CPython 2.7mmanylinux: glibc 2.12+ x86-64

File details

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

File metadata

  • Download URL: redislite-5.0.121683.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683.tar.gz
Algorithm Hash digest
SHA256 1a4080939c293b7260e5d91ba55fc7c9eee57f2f120584aa0f5f5e6dddc31a1c
MD5 fb95171fe13d6ee0c7b41aa915cdf8a8
BLAKE2b-256 6f6a9937052b8e3ef6a91bfc74b71c9dc518f13e937dfbecf9b28e163e071bbe

See more details on using hashes here.

File details

Details for the file redislite-5.0.121683-cp37-cp37m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.121683-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 85408f6883f0e66035d233d520d97778059606194bb8693a5a27430b517a44cb
MD5 5e49b3905ab5c8f6f39c09fa8f0b0299
BLAKE2b-256 2b88cd1ddf58a1f31dfd172e28eb5a0a753815592a0fd6c9de0018c97672768c

See more details on using hashes here.

File details

Details for the file redislite-5.0.121683-cp36-cp36m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.121683-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ed82469043ed6de7b31ca04fb4ec1ccfca31b69f375af021eeb1bd349e905e92
MD5 03206ed3ac99526f19b505c1dbaa88e8
BLAKE2b-256 6723461f6f31b25e830a403b745aef56141013506d69c33dfc90f7ebe8293551

See more details on using hashes here.

File details

Details for the file redislite-5.0.121683-cp35-cp35m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.121683-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 49518562c7659808ce8bdb3644d46400191053ccb89ad9c23f6dabec2aec14a5
MD5 3cd736edd54393f8d031bfaed0f34690
BLAKE2b-256 e6358b5b74d0893ae80f51a4f20b5386e93aaf674d8f76b96a87878c848a2647

See more details on using hashes here.

File details

Details for the file redislite-5.0.121683-cp34-cp34m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.121683-cp34-cp34m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 3.4m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683-cp34-cp34m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 cd4ba26fb65092c2e72f4ee5f58087249f309052beabccb75dc4636a7550ff59
MD5 db0c48b449c2d796fdc0633db6d6521e
BLAKE2b-256 0fa427cac1ad8a1817502bc0afb4ad23b04b69fa50e005fda9a8b45a886974b9

See more details on using hashes here.

File details

Details for the file redislite-5.0.121683-cp27-cp27mu-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.121683-cp27-cp27mu-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 2.7mu, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 23402cd2660a266b43107f69a6ef941ec6b2c3aa472e7746679ea98204267b7c
MD5 cef2e77ffde857b6ac9757195a344953
BLAKE2b-256 af89e1113d4c1ec05df9e5f95d10b4fbbc37b84ad64c09dfd557922c43667729

See more details on using hashes here.

File details

Details for the file redislite-5.0.121683-cp27-cp27m-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.121683-cp27-cp27m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 3.3 MB
  • Tags: CPython 2.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.3

File hashes

Hashes for redislite-5.0.121683-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 a98acea13329882a13743fc96a86b6f03194c466bccba6ac4ef026c5b395e63b
MD5 e75efa113eb450146da35c19a7c03aac
BLAKE2b-256 f88dc0952ded00f3fec9af234532da051ae73b3431fcb5a9290054ce65fbf148

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