redis
Master Redis operations across strings, hashes, lists, sets, and sorted sets with real-world examples. Learn persistence strategies, replication setup, and cluster configuration alongside performance monitoring and troubleshooting techniques.
Redis helps you master database commands, data structures, and cluster management through practical terminal examples.
AI-generated summary based on this skill's SKILL.md
Install
chaterm/terminal-skills/redis
git clone https://github.com/chaterm/terminal-skills
cp -r terminal-skills/database/redis ~/.claude/skills/redisnpx skillfed install chaterm/terminal-skills/redisFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
What are the main Redis data structures and how do I use Redis commands?
Redis supports five core data structures: strings, hashes, lists, sets, and sorted sets. Strings store simple key-value pairs using GET/SET commands. Hashes organize related fields with HGET/HSET. Lists maintain ordered elements via LPUSH/RPUSH. Sets store unique values with SADD/SMEMBERS. Sorted sets combine uniqueness with scoring using ZADD/ZRANGE. Each structure has specialized commands optimized for different access patterns and use cases.
How do I configure redis persistence with RDB and AOF?
Redis offers two persistence mechanisms. RDB (Redis Database) creates point-in-time snapshots at intervals or after a set number of writes—fast but may lose recent data. AOF (Append-Only File) logs every write operation, providing better durability but larger file sizes. Configure both in redis.conf: set 'save' directives for RDB snapshots and 'appendonly yes' for AOF. Combine them for maximum safety: RDB for recovery speed, AOF for data loss prevention.
What's the process for setting up redis master slave replication?
Redis master-slave replication synchronizes data across instances. On the slave, execute SLAVEOF master_ip master_port or configure 'slaveof' in redis.conf. The slave connects to the master, performs an initial full sync (PSYNC), then receives incremental updates. Use ROLE command to verify replication status. For high availability, combine replication with Sentinel to auto-failover if the master fails.
How can I implement redis distributed lock implementation for concurrency?
Redis distributed locks prevent concurrent access to shared resources. Set a lock key with SET key value NX EX seconds—NX ensures atomicity (only succeeds if absent), EX sets expiration to prevent deadlocks. Use a unique value (UUID) to safely delete only your lock. For complex scenarios, use Redlock algorithm across multiple Redis instances. Monitor lock contention and adjust TTL based on operation duration.
What techniques help with redis performance monitoring and troubleshooting?
Redis provides multiple monitoring tools. SLOWLOG GET captures slow commands exceeding a threshold (slowlog-max-len in config). INFO command returns memory, CPU, and replication stats. MONITOR shows real-time commands. Use redis-cli --stat for live metrics. For memory issues, MEMORY DOCTOR analyzes usage patterns. CLIENT LIST tracks connections. Enable slow query logging, set appropriate timeouts, and regularly analyze INFO output to detect bottlenecks early.
How do I detect and optimize big keys in redis?
Big keys consume excessive memory and slow operations. Detect them using redis-cli --bigkeys for a quick scan, or MEMORY DOCTOR for detailed analysis. Use STRLEN for strings, HLEN for hashes, LLEN for lists to measure sizes. Optimize by splitting large hashes into smaller ones, sharding big lists across keys, or compressing values. Monitor key sizes regularly and set alerts for anomalies to prevent performance degradation.
SKILL.md
rendered from the published skill — quoted content, verbatim
Redis 数据库管理
概述
Redis 命令、持久化、集群配置等技能。
连接管理
# 本地连接
redis-cli
# 远程连接
redis-cli -h hostname -p 6379
redis-cli -h hostname -p 6379 -a password
# 连接并选择数据库
redis-cli -n 1
# 执行单条命令
redis-cli ping
redis-cli get key
# 集群连接
redis-cli -c -h hostname -p 6379
基础命令
键操作
# 查看键
KEYS * # 所有键(生产慎用)
KEYS user:* # 匹配模式
SCAN 0 MATCH user:* COUNT 100 # 安全遍历
# 键信息
EXISTS key
TYPE key
TTL key # 剩余过期时间
PTTL key # 毫秒
# 键操作
DEL key
EXPIRE key 3600 # 设置过期时间
PERSIST key # 移除过期时间
RENAME key newkey
字符串
SET key value
SET key value EX 3600 # 带过期时间
SETNX key value # 不存在时设置
GET key
MSET key1 val1 key2 val2
MGET key1 key2
INCR counter
INCRBY counter 10
DECR counter
APPEND key " suffix"
STRLEN key
哈希
```bash HSET user:1 name "John" age 30 HGET user:1 name HMSET user:1 name "John" age 30 HMGET user:1 name age HGETALL user:1 HDEL
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 1 file
database/redis/SKILL.md