Redis built into a python package
Project description
Redislite
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
File details
Details for the file redislite-5.0.164828.tar.gz
.
File metadata
- Download URL: redislite-5.0.164828.tar.gz
- Upload date:
- Size: 1.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9968ee2920e832962e9ae54d94f432935bb7bd65d415a1918db6cb88a3a28af3 |
|
MD5 | 80a2255d331401559f48f0e713872f34 |
|
BLAKE2b-256 | 862288baa5695db35c84f00de8789eec356765512c45dcad4d04631074f5cfb2 |
File details
Details for the file redislite-5.0.164828-cp38-cp38-manylinux2014_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-cp38-cp38-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.8
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3992fc62117919d7e87cff35f0172439265c7cc68eff8bdf7dbd4c263659560 |
|
MD5 | ccda962c771f5971d2dea9fd28c095da |
|
BLAKE2b-256 | 699eacd11263a8244c86d90737d841e044445ded4b50aca8c3ffc732328d0819 |
File details
Details for the file redislite-5.0.164828-cp38-cp38-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a875848e1fa2368caf10f1f4daeb9ec91d97a5a770dd2237228f348729ef8f21 |
|
MD5 | 97b6e83995b63ccef78718a315c51a57 |
|
BLAKE2b-256 | 678b631316bc2d53fbd0ca76e57933098462ee15dc75e841d0f98f9c7b20d8ca |
File details
Details for the file redislite-5.0.164828-cp37-cp37m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-cp37-cp37m-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.7m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2238c363a6e147ffcd34981dc5c2004ff9f477ed117e06dd3c882da091d9b4cf |
|
MD5 | 008ec33eeee1fc4c803641b7f1841533 |
|
BLAKE2b-256 | 1100410ea7bd79857e7ea736e727e7db488eaaedeb301e62fbcf006356952a11 |
File details
Details for the file redislite-5.0.164828-cp37-cp37m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2789d1208094cc39735221a93fb224968299a6926078a5e92ca5222d838c876 |
|
MD5 | b12bd7eb9f119a22b4788756c7e0e599 |
|
BLAKE2b-256 | f1f3ef559038fbb207b4ce9d279fd785323d854bd821be8755745fb79af8819d |
File details
Details for the file redislite-5.0.164828-cp36-cp36m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-cp36-cp36m-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.6m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 852d1c40f690018988398ebc77f8c5de19ed4591de0bb136174c21e09c6908bc |
|
MD5 | 9245fe424d77eb010e6c798296deae29 |
|
BLAKE2b-256 | 820a58a60dd8db6862d534034f6276ef735ff5e691681cc8e6f493cb2587216f |
File details
Details for the file redislite-5.0.164828-cp36-cp36m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f4da8045d43b1b52706b863b2c7c126b27cb2b32fd4f55e808554df4e1ea5c9 |
|
MD5 | 71c1455cb8d544b6485d8f43d9b828f2 |
|
BLAKE2b-256 | a0e00bb9af5d69fedfb0531f70f8bdb23070155df9d1ffdbaae54f17230eff65 |
File details
Details for the file redislite-5.0.164828-cp35-cp35m-manylinux2014_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-cp35-cp35m-manylinux2014_x86_64.whl
- Upload date:
- Size: 4.3 MB
- Tags: CPython 3.5m
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9e1c7d08f1edbc804d2b6174879689b3147fbafe961a3b3fc5482e80c97abd0 |
|
MD5 | ff756f01b12729d7a3908d0a791a0166 |
|
BLAKE2b-256 | a060a1d517f0bf42686430cbfc41f2689558b152445169f22f557f8d32ec7cc0 |
File details
Details for the file redislite-5.0.164828-cp35-cp35m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b873034fcf6a8d8c473347833b4847af7b2f3c69dfbe201ec9d237745fc8218 |
|
MD5 | 177e4d191c726f37ce37078116cfa74c |
|
BLAKE2b-256 | 9af5766a92fbbfe4ad890d9ea9289255a0fa46846b65c24c64d6a8f772f5e511 |
File details
Details for the file redislite-5.0.164828-cp34-cp34m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0265a5e07a5f43d8f1e2e63b13c9e04255c0abe7abd9772a1a33ab5bc4157964 |
|
MD5 | ff9c28bbdc3c86172051de1f77ad9a26 |
|
BLAKE2b-256 | cd14d0f8799edd284b27e2aa8dbaf0102663009106428206a8a0d38fe47e77a0 |
File details
Details for the file redislite-5.0.164828-cp27-cp27mu-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e4f2fcb395089e9303036cb4d4b504a87c1be306ccaf5d74e3006298d091c57d |
|
MD5 | 319515854be9aba5fc93a99766d2fd08 |
|
BLAKE2b-256 | c268657314766dc5f452e28d10e999c4474739d029be640bd0629927d987e2c2 |
File details
Details for the file redislite-5.0.164828-cp27-cp27m-manylinux2010_x86_64.whl
.
File metadata
- Download URL: redislite-5.0.164828-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.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ae43a31c7870705e9fec9313a1370381482b744fd58e40156361ccf30adc646 |
|
MD5 | e11d8539054f6b7e9c2cc790efb1c3a8 |
|
BLAKE2b-256 | 079bebdbb80ad2a7319d16c389e1d3f74aff55c30bbe932487a50519a3e71e76 |