fakeredis

2.34.1 · active · verified Sat Mar 28

Fakeredis is a pure-Python implementation of the Redis Protocol API, designed primarily for testing purposes. It provides an in-memory substitute for a real Redis server, enabling developers to run tests without requiring an external Redis instance. The library offers enhanced versions of the `redis-py` and `valkey-py` Python bindings, supporting most Redis commands, including advanced features like RedisJSON and Lua scripting. Currently at version 2.34.1, it maintains an active development status with regular updates to ensure compatibility with recent `redis-py` versions and new Redis features.

Warnings

Install

Imports

Quickstart

Initialize `FakeRedis` for synchronous operations or `FakeAsyncRedis` for `asyncio` based applications. These instances mimic the `redis-py` client interface, allowing you to interact with an in-memory Redis store. By default, each instance manages its own isolated state.

import fakeredis

# Basic synchronous usage
r_sync = fakeredis.FakeRedis()
r_sync.set('mykey', 'myvalue')
print(f"Synchronous get: {r_sync.get('mykey')}")

# Basic asynchronous usage
import asyncio

async def async_example():
    r_async = fakeredis.FakeAsyncRedis()
    await r_async.set('myasync_key', 'myasync_value')
    print(f"Asynchronous get: {await r_async.get('myasync_key')}")

if __name__ == '__main__':
    asyncio.run(async_example())

view raw JSON →