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.

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.159427.tar.gz (1.9 MB view details)

Uploaded Source

Built Distributions

redislite-5.0.159427-cp38-cp38-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.12+ x86-64

redislite-5.0.159427-cp37-cp37m-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.7m manylinux: glibc 2.12+ x86-64

redislite-5.0.159427-cp36-cp36m-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.6m manylinux: glibc 2.12+ x86-64

redislite-5.0.159427-cp35-cp35m-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.5m manylinux: glibc 2.12+ x86-64

redislite-5.0.159427-cp34-cp34m-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.4m manylinux: glibc 2.12+ x86-64

redislite-5.0.159427-cp27-cp27mu-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 2.7mu manylinux: glibc 2.12+ x86-64

redislite-5.0.159427-cp27-cp27m-manylinux2010_x86_64.whl (4.4 MB view details)

Uploaded CPython 2.7m manylinux: glibc 2.12+ x86-64

File details

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

File metadata

  • Download URL: redislite-5.0.159427.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427.tar.gz
Algorithm Hash digest
SHA256 4dc83edc9e3411c5ff6837b5b3870f9ea9d48d783bb8a62017ee5fe4068f0ea6
MD5 f16babf4e47b9b367d43bf85702324f6
BLAKE2b-256 b2f240f273f28276d17e5c8412b53f91984ffa3a501a523bd903f2c91b451e5c

See more details on using hashes here.

File details

Details for the file redislite-5.0.159427-cp38-cp38-manylinux2010_x86_64.whl.

File metadata

  • Download URL: redislite-5.0.159427-cp38-cp38-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.8, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp38-cp38-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 283b52a58bfc3f989aa08f8483509f3f6d22a5faaad36e390690da47e84f74ee
MD5 c65fd64face8ad943e8da500f4006d04
BLAKE2b-256 143c7098550acabd1eb351c65c4581ac2eb8053cb1ff15378be8ec30a4b91cbd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redislite-5.0.159427-cp37-cp37m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 adb7d895b05ffcdd6595b7c6982ec83323e7a5fa82572873c89710c9d0d74c01
MD5 fc1aa10f3cbc48907b2cf983e11b103e
BLAKE2b-256 9c07adc2063f0d53234c40d5532eb6835f51490d8ad341b9cb593946aa0d6a54

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redislite-5.0.159427-cp36-cp36m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.6m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 6d0a2fb16f31f6fb3cd2fcf36f2ef26edf3cc8b0e81be5f7c6d0d23a10f531d4
MD5 e3615df5e7ffff4d9689faa996d3b002
BLAKE2b-256 b4ef1c98b27f99e641bf7fff6c8f6f53863e3bd84d4077f2dc0a06ab38c8e21e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redislite-5.0.159427-cp35-cp35m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.5m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 90172aab0d73dae1e485d4d344dcb3dbb52d06d6462294ef699a0543c72fdc05
MD5 041a2b789c022bba4c0dbfb34fb54c5f
BLAKE2b-256 1494daa13deacdc20a946ea16971e68f61993186fde09731c6ce4ec26521c2f7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redislite-5.0.159427-cp34-cp34m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 3.4m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp34-cp34m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 c318698cc2cc769c9f167d0ab10eb27e6a01aa9ca8a0c84e490553762cfffce2
MD5 9cc6f6f83affcb93a7a2ac081c92c865
BLAKE2b-256 4f005efc13924a240da5cdab6d39c958d31a1662703fb0761599c94fc5b41f42

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redislite-5.0.159427-cp27-cp27mu-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 2.7mu, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 9a5244c4bafd14c6ba796d680e3e9d71e51cc1dd5bb66a51cef3092836c755f0
MD5 d05671824f3732f73e8864df3600393e
BLAKE2b-256 472e48fc52f596e3bf1e99d261a826491837ad422acac6b1c5c64bce870ddf5d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: redislite-5.0.159427-cp27-cp27m-manylinux2010_x86_64.whl
  • Upload date:
  • Size: 4.4 MB
  • Tags: CPython 2.7m, manylinux: glibc 2.12+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.5

File hashes

Hashes for redislite-5.0.159427-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 ed01507287a95cccb0110a4b8007eddfee53b0c1bea00a91e94f6e1dad6c36f8
MD5 104a902f033b8d3ea504943532eaf9b2
BLAKE2b-256 262bc7da65ac365078bf34059dc1d3ed8aa3d8ad5d6fea172dd46d7742bb9b3b

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