<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr" -->

---
title: Testing without a server: using FakeValkey, the...
description: FakeValkey is a pure-Python, in-memory implementation of the Valkey command set that plugs into valkey-py as a client class, letting you test code without...
canonical: https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Testing without a server: using FakeValkey, the in-memory test double for Valkey | daily.dev
og:description: FakeValkey is a pure-Python, in-memory implementation of the Valkey command set that plugs into valkey-py as a client class, letting you test code without...
og:url: https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr
og:image: https://api.daily.dev/og/posts/CHcLQXtZr.png
og:image:alt: Testing without a server: using FakeValkey, the in-memory test double for Valkey
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing without a server: using FakeValkey, the in-memory test double for Valkey

**[Valkey](https://daily.dev/sources/valkey-blog)** · 8 min read · 0 upvotes · 0 comments

## Summary

FakeValkey is a pure-Python, in-memory implementation of the Valkey command set that plugs into valkey-py as a client class, letting you test code without starting a real server. It runs inside the test process with no network connection, and the two unit tests in the example finish in 0.09 seconds together on an arm64 Linux VM. The maintainer's library, fakeredis, gets about 40 million downloads per month as of September 2026. Its CI runs the same test suite against real valkey/valkey:9.1 and 8.1.8 images and against the fake to catch drift. Use a real server for unimplemented commands, multi-node behavior like replication and cluster mode, and latency or memory measurements.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://valkey.io/blog/testing-without-a-server-fakevalkey>

## Questions this post answers

### How do I test Python code that uses Valkey without running a real Valkey server?

Use FakeValkey, a pure-Python in-memory implementation of the Valkey command set from the fakeredis library, installed via pip install "fakeredis[valkey]". It subclasses valkey.Valkey so any code accepting a Valkey client accepts it, with no network connection or container needed. Two sample tests using FakeValkey as a pytest fixture ran in 0.09 seconds on an arm64 Linux VM.

_Developers wiring up Valkey test suites can track tools like fakeredis on daily.dev._

### How do I share the same fake Valkey state between two different client instances in a test?

Create a single FakeServer with server_type="valkey" and pass it to multiple FakeValkey instances, such as one for a web handler and one for a background worker; both clients then read and write the same in-memory data. Without a shared FakeServer, each FakeValkey instance gets its own isolated in-memory server and starts empty.

_Teams testing multi-component Valkey workflows can follow patterns like this via daily.dev._

### Why does my FakeValkey test fail with 'attempt to index global server (a nil value)' in a Lua script?

This happens because Valkey 8.0 introduced a 'server' global as the scripting API (keeping 'redis' as a backward-compatible alias), and FakeValkey only supports the 'server' global starting from fakeredis version 2.36.0. Upgrading fakeredis to 2.36.0 or later resolves the error for scripts written against the newer Valkey Lua API.

_Developers debugging Lua scripting errors during a Valkey upgrade can track version-specific fixes on daily.dev._

## Similar posts on daily.dev

- [Valkey · Simulating Real Workloads with valkey-benchmark](https://daily.dev/posts/valkey-simulating-real-workloads-with-valkey-benchmark-tg1fvu5bu) · Valkey · 0 upvotes · 0 comments
- [Valkey 9.1 Delivers More Performance & Enhanced Security](https://daily.dev/posts/valkey-9-1-delivers-more-performance-enhanced-security-9lzgcvzst) · Phoronix · 0 upvotes · 0 comments
- [Valkey just had a 17x year. Its lead maintainer still doesn’t want Redis to die.](https://daily.dev/posts/valkey-just-had-a-17x-year-its-lead-maintainer-still-doesn-t-want-redis-to-die--hymzgle9p) · The New Stack · 2 upvotes · 0 comments
- [\[Video Podcast\] Improving Valkey with Madelyn Olson](https://daily.dev/posts/video-podcast-improving-valkey-with-madelyn-olson-bjpwcn9zl) · InfoQ · 0 upvotes · 0 comments
- [Valkey · ValkeyConf 2026: Nobody Owns Valkey. That's Why It's Working.](https://daily.dev/posts/valkey-valkeyconf-2026-nobody-owns-valkey-that-s-why-it-s-working--sdursecws) · Valkey · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#testing](https://daily.dev/tags/testing), [#valkey](https://daily.dev/tags/valkey)

[View this post on daily.dev](https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Testing without a server: using FakeValkey, the in-memory test double for Valkey","url":"https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr"},"datePublished":"2026-10-26T15:36:18.155Z","dateModified":"2026-10-26T15:36:46.962Z","description":"FakeValkey is a pure-Python, in-memory implementation of the Valkey command set that plugs into valkey-py as a client class, letting you test code without...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8256da596b4bafa3a2085b407f562708?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/8256da596b4bafa3a2085b407f562708?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"Valkey","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"Valkey","logo":"https://media.daily.dev/image/upload/s--XXPzEmD8--/f_auto,q_auto/v1787487496/logos/valkey-blog?_a=BAMAMicg0","url":"https://daily.dev/sources/valkey-blog"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,testing,valkey","timeRequired":"PT8M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Valkey","item":"https://daily.dev/sources/valkey-blog"},{"@type":"ListItem","position":3,"name":"Testing without a server: using FakeValkey, the in-memory test double for Valkey"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/testing-without-a-server-using-fakevalkey-the-in-memory-test-double-for-valkey-chclqxtzr#faq","mainEntity":[{"@type":"Question","name":"How do I test Python code that uses Valkey without running a real Valkey server?","acceptedAnswer":{"@type":"Answer","text":"Use FakeValkey, a pure-Python in-memory implementation of the Valkey command set from the fakeredis library, installed via pip install \"fakeredis[valkey]\". It subclasses valkey.Valkey so any code accepting a Valkey client accepts it, with no network connection or container needed. Two sample tests using FakeValkey as a pytest fixture ran in 0.09 seconds on an arm64 Linux VM. Developers wiring up Valkey test suites can track tools like fakeredis on daily.dev."}},{"@type":"Question","name":"How do I share the same fake Valkey state between two different client instances in a test?","acceptedAnswer":{"@type":"Answer","text":"Create a single FakeServer with server_type=\"valkey\" and pass it to multiple FakeValkey instances, such as one for a web handler and one for a background worker; both clients then read and write the same in-memory data. Without a shared FakeServer, each FakeValkey instance gets its own isolated in-memory server and starts empty. Teams testing multi-component Valkey workflows can follow patterns like this via daily.dev."}},{"@type":"Question","name":"Why does my FakeValkey test fail with 'attempt to index global server (a nil value)' in a Lua script?","acceptedAnswer":{"@type":"Answer","text":"This happens because Valkey 8.0 introduced a 'server' global as the scripting API (keeping 'redis' as a backward-compatible alias), and FakeValkey only supports the 'server' global starting from fakeredis version 2.36.0. Upgrading fakeredis to 2.36.0 or later resolves the error for scripts written against the newer Valkey Lua API. Developers debugging Lua scripting errors during a Valkey upgrade can track version-specific fixes on daily.dev."}}]}
```

