Skip to main content

Redis built into a python package

Project description

Redislite

CI/CD Build Status Codestyle 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 3.6 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-6.2.859089.tar.gz (2.5 MB view details)

Uploaded Source

Built Distributions

redislite-6.2.859089-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

redislite-6.2.859089-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

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

File details

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

File metadata

  • Download URL: redislite-6.2.859089.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for redislite-6.2.859089.tar.gz
Algorithm Hash digest
SHA256 68aa84c38c1fa610695995f47935cc290ecfede84080b58bb6ec00459babc73e
MD5 1db534a8a1ee7eb079dffd7e80d2d8d0
BLAKE2b-256 1f2eb43f789886e60fc8eb3be53dafd9b6e36ad455eea36e176629fce5f177b8

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f5bc256df991980f9b9c090cab9a7b65644b25b068e4631ee39e58c776ee3fe
MD5 0ef570bee4386c918f0bbf05fc7d2e9b
BLAKE2b-256 8bef947f1f03ab36f71e332ccc2d8d5c4b5b0d23854c8d056ad6c63409a18dcd

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30381bcfed5a5423c9d6a7c3055f1fc7b83393707f10f2220a74a28d5c250122
MD5 e6129742d9609bbc5096c2cab8176706
BLAKE2b-256 ffd501ac7d5ab3cb2de0c1411a41996e81ae3592c66b9b3039e6da80581bbb2a

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 53534cfa411211fd3c7a1dbfda7b0947ae0325e3524a373763d28ed1455723cb
MD5 2933f4ef9bc2b6ce12d2e15b020ddb0f
BLAKE2b-256 de3d6014318f7d58f55c29691515af629e405e26d19075786d15f3200a04bbb7

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0470d61c53505d69bd0ab0b2758aabcb1f0bba5fe11a5451391f630ed9d5daf3
MD5 f903f1232e7844f9654b01b72094b96f
BLAKE2b-256 fec30db685e1fe5f02277ce5e6cdb0e69f36c257378027d602b602b11c297cbb

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 67bb73deec0a320b6c5e7740d5cd33b5926783296be38dc813fcb67c65293495
MD5 d1a85d54b63bbb0e3ae318f81b9c2322
BLAKE2b-256 2bb8242e17136b9049c8c48a6514c71ae4935cb47f6b735dda339ee63ad4e3e2

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d9a164b033ec1b4e71777e9cb7e708fb7edeabf01f45bab159b0c3b89ce37906
MD5 ed3d1b8685e9f2894b104d5d461f829f
BLAKE2b-256 24bf37ba67f10543e9991f1e23551bdb20ff964a1ed8eebd1892d641d74e5fd4

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e80cff86568a8788ae97cef7a582930c8731a2d8417b7792631f4081272ef9aa
MD5 48c1ce3eaae72392fd0458bf03c02e24
BLAKE2b-256 290d889b03adb188ffc600160fa838ed79afdf469ba7d0a272a93c44b2a16557

See more details on using hashes here.

File details

Details for the file redislite-6.2.859089-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.859089-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18a68d117424806300654019570cb20bd8ea80a1ba21b398c0425d825ae37d33
MD5 c0eee2edf655f933a1d7674769371f0e
BLAKE2b-256 9e67da427f787e940d419babae84a9446bbca949ca35beadce23d082fecc920f

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