Token导航 LogoToken导航TokenDH.com
开发执行命令github未标认证来源可访问许可证需确认审计异常

redisRedis 数据库

Agent Skill

用于辅助数据库表结构、查询语句、迁移脚本和数据维护任务。它适合让 Agent 分析 schema、编写 SQL、排查查询问题、整理索引或生成迁移建议。使用时需要明确数据库类型、连接环境和目标表,区分只读分析与写入变更;涉及删除、更新、迁移和批量导入时,应优先 dry-run、备份或事务保护,避免误操作。

总安装

915

周安装

37

GitHub Stars

18

下载量

287
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:redis(Redis 数据库)
来源仓库:https://github.com/bagelhole/devops-security-agent-skills
仓库路径:skills/redis
安装命令:
npx skills add https://github.com/bagelhole/devops-security-agent-skills --skill redis
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/bagelhole/devops-security-agent-skills --skill redis

简介

用于 Redis 内存数据库的配置、缓存、队列与限流场景优化。

  • 适合低延迟缓存、会话存储、发布订阅与分布式锁需求。
  • 支持持久化、主从复制、内存淘汰策略与慢查询分析。
  • 需 Linux 或 Docker 环境,root/sudo 权限,Redis 7.x 推荐。
  • redis 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Redis

Configure, operate, and optimize Redis for caching, queues, rate limiting, and real-time data storage.

When to Use

  • You need a low-latency in-memory cache to reduce database load.
  • Your application requires rate limiting, session storage, or leaderboards.
  • You need pub/sub messaging between services.
  • You want a distributed lock or job queue backed by an in-memory store.

Prerequisites

  • Linux server or Docker.
  • Root or sudo access for package installation.
  • Redis 7.x recommended for production.

Installation and Setup

# Debian / Ubuntu
sudo apt update
sudo apt install -y redis-server

# RHEL / Amazon Linux
sudo dnf install -y redis

# Start and enable
sudo systemctl enable --now redis-server

# Verify
redis-cli ping
# Expected output: PONG

Core Configuration

Edit /etc/redis/redis.conf:

# Network
bind 0.0.0.0
port 6379
protected-mode yes
requirepass strong_redis_password

# Memory
maxmemory 2gb
maxmemory-policy allkeys-lru

# Connections
maxclients 10000
timeout 300
tcp-keepalive 60

# Logging
loglevel notice
logfile /var/log/redis/redis-server.log

# Security — disable dangerous commands in production
rename-command FLUSHALL ""
rename-command FLUSHDB ""
rename-command CONFIG ""
rename-command DEBUG ""
sudo systemctl restart redis-server

redis-cli Commands Reference

# Connect with authentication
redis-cli -a strong_redis_password

# Connect to a remote host
redis-cli -h 10.0.0.5 -p 6379 -a strong_redis_password

String Operations

SET user:1:name "Alice"
GET user:1:name

# Set with TTL (seconds)
SETEX session:abc123 3600 '{"userId":1}'

# Set only if key does not exist (distributed lock pattern)
SET lock:order:42 "worker-1" NX EX 30

# Increment counters
INCR page:views:/home
INCRBY api:quota:user:1 -1

Hash Operations

HSET user:1 name "Alice" email "alice@example.com" plan "pro"
HGET user:1 email
HGETALL user:1
HINCRBY user:1 login_count 1

List Operations (Queues)

LPUSH queue:emails '{"to":"alice@example.com","subject":"Welcome"}'
RPOP queue:emails
LLEN queue:emails

# Blocking pop (worker pattern)
BRPOP queue:emails 30

Set and Sorted Set Operations

# Sets — unique tags
SADD article:1:tags "redis" "database" "caching"
SMEMBERS article:1:tags
SISMEMBER article:1:tags "redis"

# Sorted sets — leaderboards
ZADD leaderboard 1500 "player:1" 2300 "player:2" 1800 "player:3"
ZREVRANGE leaderboard 0 9 WITHSCORES
ZINCRBY leaderboard 100 "player:1"
ZRANK leaderboard "player:2"

Key Management

KEYS user:*             # avoid in production — use SCAN instead
SCAN 0 MATCH user:* COUNT 100
TTL session:abc123
PERSIST session:abc123
DEL user:old
EXPIRE user:1 86400
TYPE user:1

Persistence

RDB Snapshots

# redis.conf — save snapshots at intervals
save 900 1       # snapshot if >= 1 key changed in 900 seconds
save 300 10      # snapshot if >= 10 keys changed in 300 seconds
save 60 10000    # snapshot if >= 10000 keys changed in 60 seconds

dbfilename dump.rdb
dir /var/lib/redis
rdbcompression yes

AOF (Append-Only File)

appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec    # good balance of safety and performance
# Options: always (safest, slowest), everysec (recommended), no (OS decides)

# AOF rewrite thresholds
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

Recommended Production Strategy

Use both RDB and AOF together. RDB provides fast restarts and compact backups. AOF provides durability down to 1-second granularity.

save 900 1
save 300 10
appendonly yes
appendfsync everysec

Redis Sentinel (High Availability)

Sentinel monitors Redis instances and performs automatic failover.

Sentinel Configuration

# /etc/redis/sentinel.conf
port 26379
sentinel monitor mymaster 10.0.0.1 6379 2
sentinel auth-pass mymaster strong_redis_password
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
sentinel parallel-syncs mymaster 1

Run at least three Sentinel instances for quorum.

# Start Sentinel
redis-sentinel /etc/redis/sentinel.conf

# Query Sentinel
redis-cli -p 26379 SENTINEL masters
redis-cli -p 26379 SENTINEL get-master-addr-by-name mymaster
redis-cli -p 26379 SENTINEL replicas mymaster

Redis Cluster Mode

Cluster mode distributes data across multiple shards automatically.

# Create a 6-node cluster (3 masters + 3 replicas)
redis-cli --cluster create \
  10.0.0.1:6379 10.0.0.2:6379 10.0.0.3:6379 \
  10.0.0.4:6379 10.0.0.5:6379 10.0.0.6:6379 \
  --cluster-replicas 1 -a strong_redis_password

# Check cluster status
redis-cli -c -a strong_redis_password CLUSTER INFO
redis-cli -c -a strong_redis_password CLUSTER NODES

# Add a new node
redis-cli --cluster add-node 10.0.0.7:6379 10.0.0.1:6379

# Rebalance slots
redis-cli --cluster rebalance 10.0.0.1:6379
# redis.conf for cluster nodes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000

Common Patterns

Caching with TTL

# Cache a database query result for 5 minutes
SET cache:user:42:profile '{"name":"Alice","plan":"pro"}' EX 300

# Cache-aside pattern (pseudocode):
# 1. GET cache:key -> if hit, return
# 2. Query database
# 3. SET cache:key result EX 300
# 4. Return result

Rate Limiting (Sliding Window)

# Allow 100 requests per minute per user
# Using a sorted set with timestamps as scores
ZADD ratelimit:user:42 1700000000.123 "req-uuid-1"
ZREMRANGEBYSCORE ratelimit:user:42 0 1699999940.000
ZCARD ratelimit:user:42
EXPIRE ratelimit:user:42 60
# If ZCARD >= 100, reject the request

Pub/Sub Messaging

# Terminal 1 — subscriber
redis-cli -a strong_redis_password
SUBSCRIBE notifications:order-updates

# Terminal 2 — publisher
redis-cli -a strong_redis_password
PUBLISH notifications:order-updates '{"orderId":42,"status":"shipped"}'

# Pattern subscription
PSUBSCRIBE notifications:*

Distributed Locking (Redlock Pattern)

# Acquire lock
SET lock:resource:42 "worker-abc" NX EX 30
# Returns OK if acquired, nil if already held

# Release lock (use Lua script to ensure atomicity)
redis-cli -a strong_redis_password EVAL "
  if redis.call('get', KEYS[1]) == ARGV[1] then
    return redis.call('del', KEYS[1])
  else
    return 0
  end
" 1 lock:resource:42 "worker-abc"

Docker Compose Setup

# docker-compose.yml
version: "3.9"

services:
  redis:
    image: redis:7-alpine
    restart: unless-stopped
    ports:
      - "6379:6379"
    volumes:
      - redis_data:/data
      - ./redis.conf:/usr/local/etc/redis/redis.conf:ro
    command: redis-server /usr/local/etc/redis/redis.conf
    healthcheck:
      test: ["CMD", "redis-cli", "-a", "strong_redis_password", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis-sentinel:
    image: redis:7-alpine
    restart: unless-stopped
    ports:
      - "26379:26379"
    volumes:
      - ./sentinel.conf:/usr/local/etc/redis/sentinel.conf
    command: redis-sentinel /usr/local/etc/redis/sentinel.conf
    depends_on:
      redis:
        condition: service_healthy

  redis-commander:
    image: rediscommander/redis-commander:latest
    restart: unless-stopped
    ports:
      - "8081:8081"
    environment:
      REDIS_HOSTS: "local:redis:6379:0:strong_redis_password"
    depends_on:
      redis:
        condition: service_healthy

volumes:
  redis_data:
docker compose up -d
redis-cli -h 127.0.0.1 -a strong_redis_password ping

Monitoring

# Real-time stats
redis-cli -a strong_redis_password INFO stats
redis-cli -a strong_redis_password INFO memory
redis-cli -a strong_redis_password INFO replication

# Key metrics to watch
redis-cli -a strong_redis_password INFO stats | grep -E "keyspace_hits|keyspace_misses"
# Hit ratio = hits / (hits + misses) — aim for > 95%

# Memory usage breakdown
redis-cli -a strong_redis_password MEMORY STATS

# Slow log (queries > 10ms by default)
redis-cli -a strong_redis_password SLOWLOG GET 10
redis-cli -a strong_redis_password SLOWLOG LEN

# Monitor all commands in real time (debugging only — impacts performance)
redis-cli -a strong_redis_password MONITOR

# Connected clients
redis-cli -a strong_redis_password CLIENT LIST

Troubleshooting

SymptomLikely CauseFix
OOM command not allowedmaxmemory limit reachedIncrease maxmemory or set a stricter eviction policy
High latency spikesRDB save or AOF rewrite forkingUse save "" to disable RDB if AOF is enabled; tune auto-aof-rewrite-min-size
LOADING Redis is loading the dataset in memoryLarge dataset being restored on startupWait for load to complete; consider smaller dataset or faster disk
Cache hit ratio < 90%TTLs too short or working set exceeds memoryIncrease maxmemory; review TTL strategy
Sentinel not failing overFewer than quorum Sentinels reachableEnsure >= 3 Sentinels are running and network-connected
CROSSSLOT error in clusterMulti-key command spans slotsUse hash tags {user:42}:profile to colocate related keys

Related Skills

  • postgresql - Primary database that Redis caches
  • mysql - Primary database that Redis caches
  • mongodb - Document database that Redis can front
  • database-backups - Include RDB files in backup strategy

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.99%
按下载量换算98

Claude

30.53%
按下载量换算88

Cursor

17.06%
按下载量换算49

Gemini CLI

9.26%
按下载量换算27

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

未通过

权限和风险

执行命令

安装流程涉及命令执行,可能通过 npx skills add https://github.com/bagelhole/devops-security-agent-skills --skill redis 联网下载 Skill 或依赖。用户安装前应确认命令来源、仓库内容和执行环境。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills