
- Installs
- 76
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/chaterm/terminal-skills --skill redis- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads redis automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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
哈希
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 user:1 age
HEXISTS user:1 name
HKEYS user:1
HVALS user:1
HINCRBY user:1 age 1
列表
LPUSH list value # 左侧插入
RPUSH list value # 右侧插入
LPOP list
RPOP list
LRANGE list 0 -1 # 获取所有
LLEN list
LINDEX list 0
LSET list 0 newvalue
LTRIM list 0 99 # 保留前100个
BLPOP list 10 # 阻塞弹出
集合
SADD set member1 member2
SREM set member1
SMEMBERS set
SISMEMBER set member
SCARD set # 元素数量
SINTER set1 set2 # 交集
SUNION set1 set2 # 并集
SDIFF set1 set2 # 差集
SRANDMEMBER set 3 # 随机获取
有序集合
ZADD zset 100 member1 200 member2
ZREM zset member1
ZRANGE zset 0 -1 # 按分数升序
ZRANGE zset 0 -1 WITHSCORES
ZREVRANGE zset 0 -1 # 按分数降序
ZRANK zset member # 排名
ZSCORE zset member # 分数
ZCOUNT zset 100 200 # 分数范围内数量
ZINCRBY zset 10 member
持久化
RDB 快照
# 手动触发
SAVE # 阻塞
BGSAVE # 后台
# 配置 redis.conf
save 900 1 # 900秒内1次修改
save 300 10 # 300秒内10次修改
save 60 10000 # 60秒内10000次修改
dbfilename dump.rdb
dir /var/lib/redis
AOF 日志
# 配置 redis.conf
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec # always/everysec/no
# AOF 重写
BGREWRITEAOF
# 自动重写配置
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
主从复制
# 从节点配置
REPLICAOF master_host master_port
REPLICAOF NO ONE # 取消复制
# 查看复制状态
INFO replication
# redis.conf 配置
replicaof master_host master_port
masterauth master_password
replica-read-only yes
集群管理
# 创建集群
redis-cli --cluster create \
node1:6379 node2:6379 node3:6379 \
node4:6379 node5:6379 node6:6379 \
--cluster-replicas 1
# 集群信息
redis-cli -c cluster info
redis-cli -c cluster nodes
# 添加节点
redis-cli --cluster add-node new_node:6379 existing_node:6379
# 重新分片
redis-cli --cluster reshard node:6379
# 检查集群
redis-cli --cluster check node:6379
性能监控
# 服务器信息
INFO
INFO memory
INFO replication
INFO stats
INFO clients
# 实时监控
MONITOR # 实时命令(调试用)
# 慢查询
SLOWLOG GET 10
SLOWLOG LEN
SLOWLOG RESET
# 配置慢查询
CONFIG SET slowlog-log-slower-than 10000
CONFIG SET slowlog-max-len 128
# 内存分析
MEMORY USAGE key
MEMORY DOCTOR
DEBUG OBJECT key
# 客户端列表
CLIENT LIST
CLIENT KILL ID client_id
常见场景
场景 1:分布式锁
# 加锁
SET lock:resource unique_value NX EX 30
# 解锁(Lua 脚本保证原子性)
EVAL "if redis.call('get',KEYS[1]) == ARGV[1] then return redis.call('del',KEYS[1]) else return 0 end" 1 lock:resource unique_value
场景 2:限流
# 滑动窗口限流
MULTI
ZADD rate_limit:user:1 timestamp timestamp
ZREMRANGEBYSCORE rate_limit:user:1 0 (timestamp-60000)
ZCARD rate_limit:user:1
EXPIRE rate_limit:user:1 60
EXEC
场景 3:缓存穿透防护
# 布隆过滤器(需要 RedisBloom 模块)
BF.ADD filter key
BF.EXISTS filter key
# 空值缓存
SET key "" EX 60 # 缓存空值
场景 4:批量删除
# 使用 SCAN + DEL
redis-cli --scan --pattern "prefix:*" | xargs redis-cli DEL
# 使用 UNLINK(异步删除)
UNLINK key1 key2 key3
故障排查
| 问题 | 排查方法 |
|---|---|
| 内存不足 | INFO memory, MEMORY DOCTOR |
| 连接数过多 | INFO clients, CLIENT LIST |
| 响应慢 | SLOWLOG GET, 检查大 key |
| 主从延迟 | INFO replication |
| 集群故障 | CLUSTER INFO, CLUSTER NODES |
# 查找大 key
redis-cli --bigkeys
# 内存分析
redis-cli --memkeys
# 延迟测试
redis-cli --latency
redis-cli --latency-history
FAQ
What does the redis skill do?
Redis 数据库管理
How do I install redis?
Run npx skills add https://github.com/chaterm/terminal-skills --skill redis in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/redis/ (personal) or .claude/skills/redis/ (project).
Which AI agents can use redis?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is redis safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains redis?
It is published by chaterm in chaterm/terminal-skills. It has 76 recorded installs.
More from chaterm/terminal-skills
system-admin
chaterm/terminal-skills
Linux system administration and monitoring
Popular data & databases skills
supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.
prisma-client-api
prisma/skills
Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".
prisma-database-setup
prisma/skills
Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.
prisma-cli
prisma/skills
Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.
prisma-postgres
prisma/skills
Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.
prisma-driver-adapter-implementation
prisma/skills
Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.