Dev

Mock Redis Key-Value Generator

The mock Redis key-value generator produces realistic Redis SET commands with namespaced keys, fake values, and TTL expiry settings — exactly what you need when building or testing a Redis-backed caching layer. Instead of hand-writing seed data, you get copy-paste-ready commands that follow real-world naming conventions like app:session:abc123 or app:user:456, complete with EX expiry flags that mirror production patterns. Redis testing often falls flat because developers seed their instances with trivial strings like 'foo' and 'bar'. Realistic fake data — with varied key types, plausible value shapes, and a mix of TTL and non-TTL entries — lets you catch bugs in key collision logic, expiry handling, and namespace isolation that toy data would never expose. This tool is particularly useful when writing integration tests that hit a live Redis instance, building demo environments to show stakeholders, or bootstrapping a local dev setup without copying production data. Adjust the key namespace to match your application's prefix and set the count to match how many entries your test scenario requires. Generated commands work directly with the Redis CLI, redis-cli in Docker, or any client that accepts raw Redis commands. Paste them into a seed script, an .env fixture, or a beforeEach block in your test suite and you have a populated Redis instance in seconds.

How to Use

  1. Enter your application's key namespace (e.g. 'auth', 'cart') in the Key Namespace field.
  2. Set the Number of Entries to match how many Redis records your test scenario requires.
  3. Click Generate to produce a list of Redis SET commands with namespaced keys and values.
  4. Copy the output and paste it into redis-cli, a Docker exec command, or your test seed script.
  5. Re-generate as many times as needed to get varied data sets for different test cases.

Use Cases

  • Seeding a local Redis instance before running integration tests
  • Populating a demo Redis environment for stakeholder walkthroughs
  • Testing TTL expiry logic with mixed EX and no-expiry entries
  • Validating key namespace isolation between microservices
  • Generating fixture data for Redis session-store unit tests
  • Stress-testing a cache eviction policy with bulk seed commands
  • Prototyping a rate-limiter by seeding realistic counter keys
  • Teaching Redis key naming conventions in onboarding workshops

Tips

  • Use a namespace that matches your app's actual prefix so tests catch real key-collision bugs, not artificial ones.
  • Mix multiple generator runs with different namespaces (e.g. 'session' and 'ratelimit') to test cross-namespace isolation logic.
  • When pasting into redis-cli, use the --pipe flag for bulk loading rather than running each command separately — much faster.
  • Save a generated batch to a .redis fixture file and commit it to version control so integration tests are reproducible across environments.
  • Check the TTL values in the output — entries with short EX values are useful for testing expiry-triggered code paths without waiting in real time.
  • If your app uses Redis keyspace notifications, seed with this data and enable notify-keyspace-events to watch expiry events fire during tests.

FAQ

How do I generate fake Redis key-value data for testing?

Set your desired namespace and entry count, then click Generate. The tool outputs ready-to-run Redis SET commands with namespaced keys, realistic value types, and EX expiry flags. Paste them directly into redis-cli, a Docker exec command, or a seed script in your test suite.

Can I customise the Redis key namespace prefix?

Yes. Type any prefix into the Key Namespace field — for example 'payments' or 'auth' — and every generated key will use that prefix in the pattern namespace:type:id. This lets you match your actual application's key structure so tests reflect real conditions.

Are TTL expiry values included in the output?

Most commands include an EX flag with a realistic expiry in seconds — short values for session-like keys, longer ones for config or feature-flag keys. A small proportion have no TTL, which mirrors how real Redis deployments mix persistent and expiring keys.

What value types does the generator produce?

The generator outputs string values in common real-world shapes: serialised JSON objects, user IDs, session tokens, numeric counters, and boolean-style flags. This variety helps you test how your application deserialises and handles different cached value formats.

Can I use the output in a redis-cli pipeline or script?

Yes. Each line is a standalone SET command, so you can pipe the output directly to redis-cli using the --pipe flag for bulk loading, paste it into a shell script, or embed it in a test fixture as an array of command strings for a Redis client library.

How many entries should I generate for load testing?

For functional tests, 8–20 entries are usually enough to cover edge cases. For load or stress testing you will need far more — generate a batch, save it to a file, and loop or pipe it to redis-cli --pipe rather than relying on a single generator run.

Does the generator follow the colon-separated Redis key naming convention?

Yes. Keys follow the widely adopted namespace:type:identifier pattern — for example app:session:7f3a1b. This convention improves key organisation, makes SCAN pattern matching reliable, and is compatible with Redis Insight's key-tree view.

Can I use this to test Redis Cluster key slot distribution?

You can, with a caveat. In Redis Cluster, keys without hash tags are distributed by slot based on the full key name. The generated keys will spread across slots naturally. If you need keys to land on the same slot, add a hash tag like {app} manually after generating.