AGENT.md
This document provides guidance for AI agents working with Redis, including key concepts, common patterns, and best practices.
Redis is an open-source, in-memory data structure store used as a database, cache, message broker, and streaming engine. It supports various data structures such as strings, hashes, lists, sets, sorted sets, bitmaps, hyperloglogs, geospatial indexes, and streams.
Redis offers multiple persistence options:
SET key value [EX seconds] [NX|XX]
GET key
INCR key
DECR key
MGET key1 key2 ...
MSET key1 value1 key2 value2 ...
HSET key field value
HGET key field
HMGET key field1 field2 ...
HGETALL key
HINCRBY key field increment
LPUSH key value1 [value2 ...]
RPUSH key value1 [value2 ...]
LPOP key
RPOP key
LRANGE key start stop
SADD key member1 [member2 ...]
SMEMBERS key
SISMEMBER key member
SINTER key1 key2 ...
SUNION key1 key2 ...
ZADD key score1 member1 [score2 member2 ...]
ZRANGE key start stop [WITHSCORES]
ZRANK key member
ZINCRBY key increment member
DEL key1 [key2 ...]
EXISTS key1 [key2 ...]
EXPIRE key seconds
TTL key
KEYS pattern (use with caution in production)
SCAN cursor [MATCH pattern] [COUNT count]
user:1000:profile:) as separatorsuser:v2:1000SCAN over KEYS in productionMGET/MSET for batch operationsnil responses appropriatelyGET cache_key
if nil:
data = fetch_from_database()
SET cache_key data EX 3600
return data
else:
return cached_data
key = "rate_limit:user:" + user_id + ":" + current_minute
count = INCR key
if count == 1:
EXPIRE key 60
if count > limit:
return "rate limit exceeded"
SET lock_key unique_value NX EX 10
if success:
# perform critical section
# release lock only if we own it
DEL lock_key (with Lua script to verify ownership)
/content/commands/: Complete command reference/content/develop/: Development guides and tutorials/content/operate/: Operational guides for deployment and management/content/integrate/: Integration guides for various languages and frameworksRedis evolves with each version. Check the version-specific command references:
When working with Redis commands:
/content/commands//content/develop/