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

Uploaded Source

Built Distributions

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

redislite-6.2.899109-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.899109-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.899109-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.899109-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.899109-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.899109-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.899109-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.899109-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.899109.tar.gz.

File metadata

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

File hashes

Hashes for redislite-6.2.899109.tar.gz
Algorithm Hash digest
SHA256 7e966a1d7d30b594d15f7b814efb66e27c10ffa47f8866a835e0678e250af8ef
MD5 9b09cf30a7bd83b64567dabd41dc30d1
BLAKE2b-256 cbad3761b262fee614549f01bdd36013d805f970bfe66a5e7bd3976c026c27cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 974b5f154971b68a2cc80ce550462670a6e3101578f31362bf153c04fadbcbe7
MD5 43078b112e065c6f98e7ea44d74a4ce3
BLAKE2b-256 43999854edf1eba5913442a12b5908b6e80a77d0c96961e7c58e47d3e60d5c4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 52ccfbf8ea2ca946f69fa411b401047573503787800e24c7b0caced6c3184216
MD5 8d5b65eb70858286bdd655c010efbee6
BLAKE2b-256 c62280c10a756171c8adc64775ec8f12a217006448b11bdd24aadee79e2ee9eb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70d8b8fe40a15b8d5bffc8b6caee1f9dea804a89bf54e2df8642b8defab643a2
MD5 47b877ea73f6ce49cae563e445e269ae
BLAKE2b-256 e0955c2b8d70b9dd6010f1381413332cbf2c8c055a135da7853f80cd1df7cbed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 67f2e963593806645d40334b0dfe612b997e6c7a133c7b8c89beb687ec8d6c38
MD5 b8357ff04488f8081b046fdb2d75426e
BLAKE2b-256 b5dfdfcbabda9fb4c2ec208b65bbdf1720bc07ca35e2e415f59bc2a747371556

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bdf6cd35482eaacfbf339b70cc02e81dfc5da7eeab6cbdf01d4f07e89c9604e7
MD5 927edaf01f01d2fa509e90c4f725faaf
BLAKE2b-256 563f76cf0c1d9df395b7e98cc98d5696e0bae0aae6056df769d079b1ede4e141

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27315d323db94aa854c58de6f7871b80dea0863b07d8678822fd36782139e954
MD5 598d0e3b3a410ee245f1a8b5e487f274
BLAKE2b-256 4ca048f790d658467e8f1fc2b985e24408e443c84cefc6b1a78d711985e995d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c74dae3547ccd089c378b1c249e7700cba756268a84d7ed41b8df7d87a404f9e
MD5 0a95df5b387127bb30e1ba834e84d4a2
BLAKE2b-256 e010e0835a0abf004c93c4894c7b578457fb46a850ee2b14a6ffb9398220795d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for redislite-6.2.899109-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ab37a66134777a9b2a0db8055f2bbf9fd5214c05377d88b447aec7a03f5a64d4
MD5 0bb64ffc79e29687717e4964cd99a4fa
BLAKE2b-256 a828aa228be166d4795bc99d298e7d8fc077fe1eb3e894a363a82638988923ca

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