redislite

raw JSON →
6.2.912183 verified Fri May 01 auth: no python

redislite embeds a Redis server into a Python package, allowing you to run Redis without a separate server process. Current version 6.2.912183 supports Python >=3.8.0 and is actively maintained. It provides a drop-in replacement for redis-py's StrictRedis and Redis classes.

pip install redislite
error ModuleNotFoundError: No module named 'redislite'
cause redislite is not installed.
fix
Run pip install redislite.
error AttributeError: module 'redislite' has no attribute 'Redis'
cause Import error: using `import redislite` and then `redislite.Redis` instead of `from redislite import Redis`.
fix
Use from redislite import Redis.
error ValueError: The 'db' argument is not supported by redislite. Use a file path.
cause Passing a Redis database number (e.g., db=0) to the constructor, which is not supported.
fix
Pass a file path string as the first argument to persist data, or use no argument for a temporary database.
breaking In redislite, the `from_url` classmethod is not available. Use `StrictRedis.from_url()` does not exist; configure via constructor arguments instead.
fix Initialize with parameters directly: `StrictRedis(host='localhost', port=6379)` or use `StrictRedis()` for embedded server.
gotcha redislite does not support Redis Sentinel or Redis Cluster. Trying to use sentinel-related classes will fail or behave unexpectedly.
fix Use standard redis-py with a real Redis server if you need Sentinel or Cluster.
deprecated Python 3.7 and earlier are no longer supported in redislite >=6.0.0.
fix Upgrade to Python >=3.8 or pin redislite to <6.0.0.

Create a Redis client with an embedded server. The first argument is an optional path to a database file.

from redislite import StrictRedis

# Creates a Redis instance with an embedded server; data stored in a temp file
r = StrictRedis()
r.set('foo', 'bar')
print(r.get('foo'))  # b'bar'

# Custom path for persistence
r2 = StrictRedis('mydata.db')
r2.set('key', 'value')