fakeredis

Python implementation of redis API, can be used for testing purposes.

142 个版本 Python >=3.7
安装
pip install fakeredis
poetry add fakeredis
pipenv install fakeredis
conda install fakeredis
描述
fakeredis

A fast, pure-Python implementation of the Redis protocol — no server required.

PyPI version CI Coverage Downloads Python versions License Open Source Helpers

Documentation · Supported commands · Changelog · Sponsor


fakeredis is a drop-in replacement for redis-py and valkey-py that runs entirely in-memory. Write tests that depend on Redis, Valkey, DragonflyDB, or KeyDB — without spinning up a real server, a container, or a network connection.

import fakeredis

r = fakeredis.FakeStrictRedis()
r.set("foo", "bar")
r.get("foo")  # b'bar'

That's it. No server to install, no port to manage, no teardown.

✨ Why fakeredis?

  • 🚀 Zero setup — no Redis server, Docker, or network required. Pure Python.
  • 🔌 Drop-in compatible — same API as redis.Redis and redis.asyncio.Redis.
  • Fast & isolated — in-memory, so tests run quickly and start from a clean slate.
  • 🧩 Multi-backend — emulate Redis, Valkey, DragonflyDB, or KeyDB, and pin a specific server version.
  • 📦 Redis Stack support — JSON, Bloom/Cuckoo filters, TimeSeries, and Geo commands.
  • 🤝 Share or isolate state — one shared in-memory server across clients, or independent servers per test.

📥 Installation

pip install fakeredis

Optional extras enable additional command families:

pip install "fakeredis[lua]"          # EVAL / EVALSHA scripting
pip install "fakeredis[json]"         # JSON.* commands
pip install "fakeredis[bf]"           # Bloom / Cuckoo / Count-Min / Top-K filters
pip install "fakeredis[probabilistic]"  # alias for the probabilistic filters
pip install "fakeredis[valkey]"       # Valkey client compatibility

🚀 Quickstart

Use it like redis.Redis:

import fakeredis

r = fakeredis.FakeStrictRedis()
r.lpush("queue", "a", "b", "c")
r.lrange("queue", 0, -1)  # [b'c', b'b', b'a']

Share one in-memory server between clients:

server = fakeredis.FakeServer()
r1 = fakeredis.FakeStrictRedis(server=server)
r2 = fakeredis.FakeStrictRedis(server=server)

r1.set("greeting", "hello")
r2.get("greeting")  # b'hello' — same underlying data

Async is supported too:

import fakeredis

async def main():
    r = fakeredis.FakeAsyncRedis()
    await r.set("foo", "bar")
    await r.get("foo")  # b'bar'

Pin a server type and version:

# Behave like Redis 6...
r = fakeredis.FakeStrictRedis(version=6)
# ...or like Valkey
r = fakeredis.FakeStrictRedis(server_type="valkey")

Using it in tests (pytest)

import pytest
import fakeredis

@pytest.fixture
def redis_client():
    return fakeredis.FakeStrictRedis()

def test_cache_set(redis_client):
    redis_client.set("user:1", "alice")
    assert redis_client.get("user:1") == b"alice"

See the official documentation for the full list of supported commands and configuration options.

❤️ Sponsor

fakeredis-py is developed and maintained for free. If it saves you time, please consider becoming a sponsor — it directly supports continued development.

🤝 Contributing

Contributions are welcome! Check out the contributing guide and the open issues to get started.

版本列表
2.36.2 2026-06-17
2.36.1 2026-06-07
2.36.0 2026-05-29
2.35.1 2026-04-12
2.35.0 2026-04-09
2.34.1 2026-02-25
2.34.0 2026-02-16
2.33.0 2025-12-16
2.32.1 2025-11-06
2.32.0 2025-10-07
2.31.3 2025-09-22
2.31.1 2025-08-31
2.31.0 2025-08-11
2.30.3 2025-07-29
2.30.2 2025-07-28
2.30.1 2025-06-19
2.30.0 2025-06-16
2.29.0 2025-05-06
2.28.1 2025-04-02
2.28.0 2025-03-29
2.27.0 2025-02-11
2.26.2 2024-12-17
2.26.1 2024-10-28
2.26.0 2024-10-24
2.25.1 2024-09-30
2.25.0 2024-09-28
2.24.1 2024-08-26
2.24.0 2024-08-24
2.23.5 2024-08-03
2.23.4 2024-07-30
2.23.3 2024-06-29
2.23.2 2024-05-18
2.23.1 2024-05-12
2.23.0 2024-05-07
2.22.0 2024-04-19
2.21.3 2024-03-12
2.21.2 2024-03-10
2.21.1 2024-02-15
2.21.0 2024-01-31
2.20.1 2023-12-13
2.20.0 2023-10-21
2.19.0 2023-09-25
2.18.1 2023-09-08
2.18.0 2023-08-14
2.17.0 2023-07-18
2.16.0 2023-07-04
2.15.0 2023-06-19
2.14.1 2023-06-06
2.14.0 2023-06-05
2.13.0 2023-05-22
2.12.1 2023-05-11
2.12.0 2023-05-08
2.11.2 2023-04-29
2.11.1 2023-04-25
2.11.0 2023-04-22
2.10.3 2023-04-03
2.10.2 2023-03-22
2.10.1 2023-03-15
2.10.0 2023-03-04
2.9.2 2023-02-20
2.9.1 2023-02-20
2.9.0 2023-02-14
2.8.0 2023-02-11
2.7.1 2023-02-04
2.7.0 2023-02-03
2.6.0 2023-01-27
2.5.1 2023-01-27
2.5.0 2023-01-22
2.4.0 2022-12-24
2.3.0 2022-12-15
2.2.0 2022-12-04
2.1.0 2022-12-01
2.0.0 2022-11-18
1.10.2 2023-04-03
1.10.1 2022-11-08
1.10.0 2022-10-25
1.9.4 2022-10-15
1.9.3 2022-09-27
1.9.2 2022-09-27
1.9.1 2022-09-04
1.9.0 2022-07-31
1.8.2 2022-07-23
1.8.1 2022-06-09
1.8 2022-05-27
1.7.6 2022-05-25
1.7.5 2022-05-14
1.7.4 2022-05-07
1.7.1 2022-02-14
1.7.0 2021-11-28
1.6.1 2021-09-08
1.6.0 2021-08-16
1.5.2 2021-06-07
1.5.1 2021-05-27
1.5.0 2021-03-24
1.4.5 2020-11-24
1.4.4 2020-10-19
1.4.3 2020-08-18
1.4.2 2020-08-04
1.4.1 2020-05-04
1.4.0 2020-04-02
1.3.1 2020-03-30
1.3.0 2020-03-17
1.2.1 2020-02-14
1.2.0 2020-02-04
1.1.1 2020-02-03
1.1.0 2019-11-29
1.0.5 2019-09-05
1.0.4 2019-08-14
1.0.3 2019-03-25
1.0.2 2019-02-18
1.0.1 2019-02-14
1.0 2019-01-24
1.0rc1 2019-01-14
1.0b1 2019-01-07
0.16.0 2018-11-28
0.15.0 2018-11-08
0.14.0 2018-09-25
0.13.1 2018-09-10
0.12.0 2018-08-02
0.11.0 2018-06-21
0.10.3 2018-05-10
0.10.2 2018-04-03
0.10.1 2018-03-22
0.9.0 2017-10-13
0.8.2 2016-12-07
0.8.1 2016-08-16
0.8.0 2016-08-16
0.7.0 2016-03-17
0.6.2 2015-07-06
0.6.1 2015-03-12
0.6.0 2015-02-20
0.5.1 2014-08-28
0.5.0 2014-08-28
0.4.3 2014-08-01
0.4.2 2014-02-20
0.4.1 2013-10-19
0.4.0 2013-08-06
0.3.1 2013-03-10
0.3.0 2012-11-18
0.2.0 2012-04-18
0.1.1 2012-03-14
0.1 2012-03-14