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

Uploaded Source

Built Distributions

redislite-6.2.912183-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

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

Uploaded PyPymanylinux: glibc 2.17+ x86-64

redislite-6.2.912183-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

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

File metadata

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

File hashes

Hashes for redislite-6.2.912183.tar.gz
Algorithm Hash digest
SHA256 40642495cc53bd5ca3cc186355a7235795ef4b36dd167cb77c7e6837d23e5dd6
MD5 140977b2e0c2388a478776ef61de51da
BLAKE2b-256 af7db6fc82af45ed2aa31f6c8b2035df009ff9fd8be01ad8a691155cc167f1f2

See more details on using hashes here.

File details

Details for the file redislite-6.2.912183-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.912183-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58617b4d5d57b8f799188178b069a41b64c19e970f733c68cdc92190b417884c
MD5 a25c34aa5beda3571ac3ee54c8bbd41a
BLAKE2b-256 001c6b8eeab46b7e1928f88a1a35613a750221664083566d7150eefc0e751802

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.912183-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 157ba9854a42e990ca94583527c454c97f5468ff18f7e48588bc1ed85f175056
MD5 fc1504e94e8c14408257ac6b994c1400
BLAKE2b-256 ac39d759b673d6b01d2936010aaa5bf38f1b91b4e452dc7fab1630223bf7ad98

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.912183-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4f75bf06cf0adff5fb51fd1364e6a1bef379980489c6b2721a882a7f336c62aa
MD5 76e05129645318acd5ab8c111c3f5ed6
BLAKE2b-256 c0e0fc4c3feeaea510dd30141339e2d686312e2e9ccb7ad2997c495b0de268cd

See more details on using hashes here.

File details

Details for the file redislite-6.2.912183-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for redislite-6.2.912183-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6610f867c2c1b2022613c093d56cfe8293bdf6e081d2259d62b5f5318487c30e
MD5 f72464e8b6a45572e15852f9bb2f588b
BLAKE2b-256 0bb995ce807b397428704bfc01769848d0caa8417e7d3753785ccc14c3b05097

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.912183-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d5ed8af4d03225a9b19e279d40f8d8feae872f87a9cd9f017751864fe7b224c6
MD5 232dad0b881cd23ea0133cfd6e4eb02f
BLAKE2b-256 212f13e658f12163e716557d057bd7975dcef3b048dc03424418cc1e7b5f6b63

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.912183-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 830cdb0551ba54ebb3f7b846361a406297d83599b12d46cfab68943421adeac7
MD5 ea1ddb0bbf5e76f3efbb54d136c339bd
BLAKE2b-256 9c07255f52ac6ed075f0ae9c9ecbdb7247853c30fc7bbbd3e78f5560085906b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.912183-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5194556dd991515d70cbb5671d7d28ea02e37ee1f82bc684c2fef0138469ae78
MD5 5f34c3dc5203e8bfdd3ee4d605bc0778
BLAKE2b-256 fc8e143439ae8518f362e5785006fc48834e232ed9601ce58ae8a26b878744d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.912183-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 17329cb71bd2e20caf2bdbed141b95e47c5754e12fad66241a6477a3e45f8a8d
MD5 4328e73bf691fc4613b7f8f7c2bbc41a
BLAKE2b-256 c8c4043fbcb1dacf09d5d11ae903e7e02e9527e83a0f2a39201a7b0047e49c11

See more details on using hashes here.

Supported by

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