How to Query Redis Using Natural Language
Redis is fast, flexible, and deliberately low-level. That low-level nature is a feature when you're building high-performance applications — but it becomes friction when you want to answer a quick question about your data. Remembering when to use ZRANGEBYSCORE vs ZRANGE BYSCORE, or how to safely iterate keys with SCAN instead of KEYS, creates a knowledge barrier even for experienced engineers.
Natural language querying removes that barrier. Type a question in plain English and have the Redis command generated automatically. This guide explains how it works with Insight O' Mate — a privacy-first AI database assistant for NoSQL databases.
What is natural language Redis querying?
It is the process of translating a plain-English question into the correct Redis command (or sequence of commands), including the right syntax for your Redis version.
For example:
"Show me all members of the leaderboard with a score above 5000."
becomes:
# Redis 6.2+ syntax
ZRANGEBYSCORE leaderboard 5000 +inf WITHSCORES
# Equivalent with ZRANGE (Redis 6.2+)
ZRANGE leaderboard 5000 +inf BYSCORE WITHSCORES
You describe the result. The AI generates the correct command.
How the translation works
1. Key pattern detection. Insight O' Mate scans a sample of your Redis keys (using SCAN with a reasonable count limit) to understand the key naming patterns and data structures in use. Your key values are never read.
2. Query generation. Your prompt and the key patterns are sent to a stateless NLP engine. The engine determines the correct Redis data structure (String, Hash, List, Set, ZSet, Stream) and generates the appropriate read command.
3. Local execution. The command runs locally on your machine via a direct Redis connection. Your Redis data never passes through any Insight O' Mate server.
Example queries and generated Redis commands
Hash — get a user profile
Prompt: Get the full profile for user 1001.
HGETALL user:1001
Sample response:
1) "name"
2) "Priya Sharma"
3) "email"
4) "priya@example.com"
5) "plan"
6) "pro"
7) "createdAt"
8) "2024-11-15T10:22:00Z"
Sorted set — leaderboard range
Prompt: Who are the top 5 players in the game leaderboard?
ZREVRANGE game:leaderboard 0 4 WITHSCORES
Sorted set — score range
Prompt: Which sessions have a TTL score between 100 and 500?
ZRANGEBYSCORE sessions:ttl 100 500 WITHSCORES
Set — members
Prompt: What permissions does the admin role have?
SMEMBERS role:admin:permissions
List — recent events
Prompt: Show me the last 20 events in the activity feed.
LRANGE feed:activity 0 19
Key pattern scan
Prompt: How many keys match the pattern session:*?
# Safe production approach — iterates without blocking
SCAN 0 MATCH session:* COUNT 100
# (Repeat with the returned cursor until cursor = 0)
Note: Insight O' Mate uses
SCANinstead ofKEYSfor pattern searches to avoid blocking your Redis instance on large keyspaces.
Redis data structures and supported commands
| Data structure | Commands generated |
|---|---|
| String | GET, MGET, STRLEN |
| Hash | HGETALL, HGET, HMGET, HKEYS, HVALS, HLEN |
| List | LRANGE, LLEN, LINDEX |
| Set | SMEMBERS, SCARD, SISMEMBER, SRANDMEMBER |
| Sorted Set | ZRANGE, ZREVRANGE, ZRANGEBYSCORE, ZREVRANGEBYSCORE, ZSCORE, ZRANK, ZCARD, ZCOUNT |
| Stream | XREAD, XLEN, XRANGE |
| Key patterns | SCAN with MATCH and COUNT |
Not generated: SET, DEL, FLUSHDB, FLUSHALL, or any write/destructive commands.
Version-aware command generation
Redis 7.x introduced changes to ZRANGE syntax, and older syntax (ZRANGEBYSCORE) was deprecated. Insight O' Mate detects your Redis server version and generates commands compatible with your version — so you don't need to track deprecation notices.
Privacy and security
- Your Redis connection string is stored in your OS keychain — never transmitted
- Your Redis values never leave your machine
- Only your prompt and key name patterns are sent to the NLP engine
- The NLP engine is stateless — no prompts are logged
Insight O' Mate uses SCAN (not KEYS) for key inspection, which is safe to run on production Redis instances because it does not block the server.
Setting up Redis with Insight O' Mate
- Download Insight O' Mate
- In the app, go to Connections → Add Redis
- Enter your Redis connection URL:
- Local:
redis://localhost:6379 - With auth:
redis://:password@localhost:6379 - TLS:
rediss://user:password@host:6380
- Local:
- Type your first question
Works with Redis Cloud, Redis Enterprise, self-hosted Redis, and Valkey.
Redis querying tips
- Use your key naming convention. If your keys follow
user:{id}:profile, mention "user profile" in your question. - Specify the data structure when ambiguous. "From the sorted set leaderboard..." helps the AI choose the right command family.
SCANis safe for production. UnlikeKEYS, it iterates non-blockingly.- Check the generated command before running it. You can always inspect and edit the Redis command in the Insight O' Mate interface.