upstash-redis-kv by intellectronica/agent-skills
npx skills add https://github.com/intellectronica/agent-skills --skill upstash-redis-kv通过 REST 接口与 Upstash 的 Redis 兼容键值存储进行交互。
bun run scripts/upstash-client.ts <command> [args...]
重要提示:始终使用 bun run 运行,不要直接运行。
脚本默认使用以下环境变量:
UPSTASH_REDIS_REST_URL - Upstash REST API URLUPSTASH_REDIS_REST_TOKEN - Upstash REST API 令牌如果用户从其他来源(对话上下文、文件等)提供了凭据,请使用 --url 和 --token 标志来覆盖环境变量:
bun run scripts/upstash-client.ts --url "https://..." --token "AX..." GET mykey
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
优先级:命令行标志 > 环境变量
# 获取/设置
GET <key>
SET <key> <value> [--ex seconds] [--px ms] [--nx] [--xx] [--keepttl] [--get]
SETNX <key> <value> # 仅当键不存在时设置
SETEX <key> <seconds> <value> # 设置并指定过期时间
# 多键操作(键/值对)
MGET <key1> [key2...]
MSET <key1> <val1> [key2 val2...]
MSETNX <key1> <val1> [key2 val2...] # 仅当所有键都不存在时设置
# 计数器
INCR <key>
INCRBY <key> <increment>
INCRBYFLOAT <key> <increment>
DECR <key>
DECRBY <key> <decrement>
# 字符串操作
APPEND <key> <value>
STRLEN <key>
GETRANGE <key> <start> <end>
SETRANGE <key> <offset> <value>
哈希存储字段-值对。将字段和值作为交替参数传递:
# 设置哈希字段(字段/值对)
HSET <key> <field1> <val1> [field2 val2...]
HSETNX <key> <field> <value> # 仅当字段不存在时设置
# 获取哈希字段
HGET <key> <field>
HMGET <key> <field1> [field2...]
HGETALL <key>
# 哈希操作
HDEL <key> <field1> [field2...]
HEXISTS <key> <field>
HKEYS <key>
HVALS <key>
HLEN <key>
HINCRBY <key> <field> <increment>
HINCRBYFLOAT <key> <field> <increment>
HSCAN <key> <cursor> [MATCH pattern] [COUNT count]
示例:
# 存储用户数据
bun run scripts/upstash-client.ts HSET user:1 name "John" email "john@example.com" age 30
# 获取单个字段
bun run scripts/upstash-client.ts HGET user:1 name
# 获取所有字段
bun run scripts/upstash-client.ts HGETALL user:1
# 递增数字字段
bun run scripts/upstash-client.ts HINCRBY user:1 age 1
列表是有序集合。值可以从左(头部)或右(尾部)推入/弹出:
# 推入元素
LPUSH <key> <val1> [val2...] # 推入到头部
RPUSH <key> <val1> [val2...] # 推入到尾部
LPUSHX <key> <val1> [val2...] # 仅当列表存在时推入
RPUSHX <key> <val1> [val2...]
# 弹出元素
LPOP <key> [count]
RPOP <key> [count]
# 访问元素
LRANGE <key> <start> <stop> # 获取范围(0 = 第一个,-1 = 最后一个)
LLEN <key>
LINDEX <key> <index>
# 修改
LSET <key> <index> <value>
LREM <key> <count> <value> # 移除指定数量的匹配项
LTRIM <key> <start> <stop> # 仅保留指定范围
LINSERT <key> <BEFORE|AFTER> <pivot> <value>
LPOS <key> <value>
LMOVE <src> <dst> <LEFT|RIGHT> <LEFT|RIGHT>
示例:
# 创建任务队列
bun run scripts/upstash-client.ts RPUSH tasks "task1" "task2" "task3"
# 获取所有任务
bun run scripts/upstash-client.ts LRANGE tasks 0 -1
# 从队列前端弹出任务(FIFO 队列)
bun run scripts/upstash-client.ts LPOP tasks
# 从队列后端弹出任务(LIFO 栈)
bun run scripts/upstash-client.ts RPOP tasks
集合存储唯一、无序的成员:
# 添加/移除成员
SADD <key> <member1> [member2...]
SREM <key> <member1> [member2...]
# 查询
SMEMBERS <key>
SISMEMBER <key> <member>
SMISMEMBER <key> <member1> [member2...]
SCARD <key>
# 随机访问
SPOP <key> [count]
SRANDMEMBER <key> [count]
# 集合操作
SINTER <key1> [key2...]
SINTERSTORE <dest> <key1> [key2...]
SUNION <key1> [key2...]
SUNIONSTORE <dest> <key1> [key2...]
SDIFF <key1> [key2...]
SDIFFSTORE <dest> <key1> [key2...]
SMOVE <src> <dst> <member>
SSCAN <key> <cursor> [MATCH pattern] [COUNT count]
示例:
# 添加标签
bun run scripts/upstash-client.ts SADD article:1:tags "javascript" "redis" "nodejs"
# 检查成员资格
bun run scripts/upstash-client.ts SISMEMBER article:1:tags "javascript"
# 获取所有成员
bun run scripts/upstash-client.ts SMEMBERS article:1:tags
# 查找文章之间的共同标签
bun run scripts/upstash-client.ts SINTER article:1:tags article:2:tags
有序集合存储带有分数的成员,用于排名:
# 添加成员(分数/成员对)
ZADD <key> <score1> <member1> [score2 member2...] [--nx] [--xx] [--gt] [--lt] [--ch]
# 移除
ZREM <key> <member1> [member2...]
ZREMRANGEBYRANK <key> <start> <stop>
ZREMRANGEBYSCORE <key> <min> <max>
# 分数和排名
ZSCORE <key> <member>
ZMSCORE <key> <member1> [member2...]
ZRANK <key> <member> # 排名(从低到高)
ZREVRANK <key> <member> # 排名(从高到低)
ZINCRBY <key> <increment> <member>
# 范围查询
ZRANGE <key> <start> <stop> [--withscores] [--rev] [--byscore] [--bylex]
ZRANGEBYSCORE <key> <min> <max> [--withscores] [--limit off,count]
ZREVRANGE <key> <start> <stop> [--withscores]
ZREVRANGEBYSCORE <key> <max> <min> [--withscores] [--limit off,count]
# 计数
ZCARD <key>
ZCOUNT <key> <min> <max>
# 弹出
ZPOPMIN <key> [count]
ZPOPMAX <key> [count]
# 集合操作
ZINTERSTORE <dest> <numkeys> <key1> [key2...]
ZUNIONSTORE <dest> <numkeys> <key1> [key2...]
ZSCAN <key> <cursor> [MATCH pattern] [COUNT count]
示例:
# 创建排行榜(分数 成员 对)
bun run scripts/upstash-client.ts ZADD leaderboard 1000 "player1" 1500 "player2" 1200 "player3"
# 获取前 3 名及其分数(最高分在前)
bun run scripts/upstash-client.ts ZRANGE leaderboard 0 2 --rev --withscores
# 获取玩家排名
bun run scripts/upstash-client.ts ZREVRANK leaderboard "player2"
# 增加玩家分数
bun run scripts/upstash-client.ts ZINCRBY leaderboard 100 "player1"
# 获取分数在 1000 到 1500 之间的玩家
bun run scripts/upstash-client.ts ZRANGEBYSCORE leaderboard 1000 1500 --withscores
# 删除
DEL <key1> [key2...]
UNLINK <key1> [key2...] # 异步删除
# 存在性/类型
EXISTS <key1> [key2...]
TYPE <key>
# 过期
EXPIRE <key> <seconds>
EXPIREAT <key> <timestamp>
PEXPIRE <key> <milliseconds>
PEXPIREAT <key> <timestamp>
TTL <key>
PTTL <key>
PERSIST <key> # 移除过期时间
# 重命名
RENAME <key> <newkey>
RENAMENX <key> <newkey>
# 搜索
KEYS <pattern> # 在生产环境中谨慎使用
SCAN <cursor> [MATCH pattern] [COUNT count]
# 其他
COPY <src> <dst>
DUMP <key>
TOUCH <key1> [key2...]
RANDOMKEY
OBJECT ENCODING|FREQ|IDLETIME|REFCOUNT <key>
示例:
# 设置键并指定 1 小时过期时间
bun run scripts/upstash-client.ts SET session:abc "data"
bun run scripts/upstash-client.ts EXPIRE session:abc 3600
# 或者在一个命令中完成
bun run scripts/upstash-client.ts SET session:abc "data" --ex 3600
# 检查 TTL
bun run scripts/upstash-client.ts TTL session:abc
# 扫描匹配模式的键
bun run scripts/upstash-client.ts SCAN 0 MATCH "user:*" COUNT 100
PING [message]
ECHO <message>
DBSIZE
TIME
INFO [section]
FLUSHDB # 删除当前数据库中的所有键(危险)
FLUSHALL # 删除所有数据库中的所有键(危险)
--ex <seconds> # 以秒为单位设置过期时间
--px <ms> # 以毫秒为单位设置过期时间
--exat <ts> # 在 Unix 时间戳(秒)过期
--pxat <ts> # 在 Unix 时间戳(毫秒)过期
--nx # 仅当键不存在时设置
--xx # 仅当键存在时设置
--keepttl # 保留现有的 TTL
--get # 返回旧值
--nx # 仅添加新成员
--xx # 仅更新现有成员
--gt # 仅在新分数 > 当前分数时更新
--lt # 仅在新分数 < 当前分数时更新
--ch # 返回已更改元素的数量
--withscores # 输出中包含分数
--byscore # 按分数范围而非排名范围
--bylex # 按字典顺序范围
--rev # 反向顺序
--limit off,count # 限制结果数量(例如,--limit 0,10)
(nil)在执行任何破坏性操作(写入、修改或删除)之前,您必须请求用户确认。这包括:
写入操作:
修改操作:
删除操作:
TTL/重命名操作:
确认提示示例:
"我即将对
user:1执行 HSET 操作,字段为{name: "John", email: "john@example.com"}。是否继续?"
如果用户表示不希望被请求确认,请尊重此决定,并在所有后续操作中遵循。指示词包括:
一旦激活 YOLO 模式,无需询问即可执行破坏性操作,但仍需告知用户已执行的操作。
示例:
已设置
user:1的字段为{name: "John", email: "john@example.com"}- 完成。
如果凭据缺失或无效,脚本将退出并显示错误消息。请确保用户已配置以下任一方式:
UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN)--url 和 --token 标志提供凭据每周安装量
100
代码仓库
GitHub 星标数
228
首次出现
2026年2月4日
安全审计
已安装于
codex84
opencode83
gemini-cli82
claude-code79
cursor78
github-copilot74
Interact with Upstash's Redis-compatible key-value store using the REST interface.
bun run scripts/upstash-client.ts <command> [args...]
IMPORTANT : Always run with bun run, not directly.
The script uses these environment variables by default:
UPSTASH_REDIS_REST_URL - The Upstash REST API URLUPSTASH_REDIS_REST_TOKEN - The Upstash REST API tokenIf the user provides credentials from another source (conversation context, a file, etc.), use the --url and --token flags to override environment variables:
bun run scripts/upstash-client.ts --url "https://..." --token "AX..." GET mykey
Priority : Command-line flags > Environment variables
# Get/Set
GET <key>
SET <key> <value> [--ex seconds] [--px ms] [--nx] [--xx] [--keepttl] [--get]
SETNX <key> <value> # Set if not exists
SETEX <key> <seconds> <value> # Set with expiration
# Multiple keys (key/value pairs)
MGET <key1> [key2...]
MSET <key1> <val1> [key2 val2...]
MSETNX <key1> <val1> [key2 val2...] # Set all if none exist
# Counters
INCR <key>
INCRBY <key> <increment>
INCRBYFLOAT <key> <increment>
DECR <key>
DECRBY <key> <decrement>
# String manipulation
APPEND <key> <value>
STRLEN <key>
GETRANGE <key> <start> <end>
SETRANGE <key> <offset> <value>
Hashes store field-value pairs. Pass fields and values as alternating arguments:
# Set hash fields (field/value pairs)
HSET <key> <field1> <val1> [field2 val2...]
HSETNX <key> <field> <value> # Set field if not exists
# Get hash fields
HGET <key> <field>
HMGET <key> <field1> [field2...]
HGETALL <key>
# Hash operations
HDEL <key> <field1> [field2...]
HEXISTS <key> <field>
HKEYS <key>
HVALS <key>
HLEN <key>
HINCRBY <key> <field> <increment>
HINCRBYFLOAT <key> <field> <increment>
HSCAN <key> <cursor> [MATCH pattern] [COUNT count]
Examples:
# Store user data
bun run scripts/upstash-client.ts HSET user:1 name "John" email "john@example.com" age 30
# Get single field
bun run scripts/upstash-client.ts HGET user:1 name
# Get all fields
bun run scripts/upstash-client.ts HGETALL user:1
# Increment numeric field
bun run scripts/upstash-client.ts HINCRBY user:1 age 1
Lists are ordered collections. Values are pushed/popped from left (head) or right (tail):
# Push elements
LPUSH <key> <val1> [val2...] # Push to head
RPUSH <key> <val1> [val2...] # Push to tail
LPUSHX <key> <val1> [val2...] # Push if list exists
RPUSHX <key> <val1> [val2...]
# Pop elements
LPOP <key> [count]
RPOP <key> [count]
# Access elements
LRANGE <key> <start> <stop> # Get range (0 = first, -1 = last)
LLEN <key>
LINDEX <key> <index>
# Modify
LSET <key> <index> <value>
LREM <key> <count> <value> # Remove count occurrences
LTRIM <key> <start> <stop> # Keep only range
LINSERT <key> <BEFORE|AFTER> <pivot> <value>
LPOS <key> <value>
LMOVE <src> <dst> <LEFT|RIGHT> <LEFT|RIGHT>
Examples:
# Create a task queue
bun run scripts/upstash-client.ts RPUSH tasks "task1" "task2" "task3"
# Get all tasks
bun run scripts/upstash-client.ts LRANGE tasks 0 -1
# Pop task from front (FIFO queue)
bun run scripts/upstash-client.ts LPOP tasks
# Pop task from back (LIFO stack)
bun run scripts/upstash-client.ts RPOP tasks
Sets store unique, unordered members:
# Add/remove members
SADD <key> <member1> [member2...]
SREM <key> <member1> [member2...]
# Query
SMEMBERS <key>
SISMEMBER <key> <member>
SMISMEMBER <key> <member1> [member2...]
SCARD <key>
# Random access
SPOP <key> [count]
SRANDMEMBER <key> [count]
# Set operations
SINTER <key1> [key2...]
SINTERSTORE <dest> <key1> [key2...]
SUNION <key1> [key2...]
SUNIONSTORE <dest> <key1> [key2...]
SDIFF <key1> [key2...]
SDIFFSTORE <dest> <key1> [key2...]
SMOVE <src> <dst> <member>
SSCAN <key> <cursor> [MATCH pattern] [COUNT count]
Examples:
# Add tags
bun run scripts/upstash-client.ts SADD article:1:tags "javascript" "redis" "nodejs"
# Check membership
bun run scripts/upstash-client.ts SISMEMBER article:1:tags "javascript"
# Get all members
bun run scripts/upstash-client.ts SMEMBERS article:1:tags
# Find common tags between articles
bun run scripts/upstash-client.ts SINTER article:1:tags article:2:tags
Sorted sets store members with scores for ranking:
# Add members (score/member pairs)
ZADD <key> <score1> <member1> [score2 member2...] [--nx] [--xx] [--gt] [--lt] [--ch]
# Remove
ZREM <key> <member1> [member2...]
ZREMRANGEBYRANK <key> <start> <stop>
ZREMRANGEBYSCORE <key> <min> <max>
# Scores and ranks
ZSCORE <key> <member>
ZMSCORE <key> <member1> [member2...]
ZRANK <key> <member> # Rank (low to high)
ZREVRANK <key> <member> # Rank (high to low)
ZINCRBY <key> <increment> <member>
# Range queries
ZRANGE <key> <start> <stop> [--withscores] [--rev] [--byscore] [--bylex]
ZRANGEBYSCORE <key> <min> <max> [--withscores] [--limit off,count]
ZREVRANGE <key> <start> <stop> [--withscores]
ZREVRANGEBYSCORE <key> <max> <min> [--withscores] [--limit off,count]
# Counting
ZCARD <key>
ZCOUNT <key> <min> <max>
# Pop
ZPOPMIN <key> [count]
ZPOPMAX <key> [count]
# Set operations
ZINTERSTORE <dest> <numkeys> <key1> [key2...]
ZUNIONSTORE <dest> <numkeys> <key1> [key2...]
ZSCAN <key> <cursor> [MATCH pattern] [COUNT count]
Examples:
# Create leaderboard (score member pairs)
bun run scripts/upstash-client.ts ZADD leaderboard 1000 "player1" 1500 "player2" 1200 "player3"
# Get top 3 with scores (highest first)
bun run scripts/upstash-client.ts ZRANGE leaderboard 0 2 --rev --withscores
# Get player's rank
bun run scripts/upstash-client.ts ZREVRANK leaderboard "player2"
# Increment player's score
bun run scripts/upstash-client.ts ZINCRBY leaderboard 100 "player1"
# Get players with scores between 1000 and 1500
bun run scripts/upstash-client.ts ZRANGEBYSCORE leaderboard 1000 1500 --withscores
# Delete
DEL <key1> [key2...]
UNLINK <key1> [key2...] # Async delete
# Existence/Type
EXISTS <key1> [key2...]
TYPE <key>
# Expiration
EXPIRE <key> <seconds>
EXPIREAT <key> <timestamp>
PEXPIRE <key> <milliseconds>
PEXPIREAT <key> <timestamp>
TTL <key>
PTTL <key>
PERSIST <key> # Remove expiration
# Rename
RENAME <key> <newkey>
RENAMENX <key> <newkey>
# Search
KEYS <pattern> # Use with caution in production
SCAN <cursor> [MATCH pattern] [COUNT count]
# Other
COPY <src> <dst>
DUMP <key>
TOUCH <key1> [key2...]
RANDOMKEY
OBJECT ENCODING|FREQ|IDLETIME|REFCOUNT <key>
Examples:
# Set key with 1 hour expiration
bun run scripts/upstash-client.ts SET session:abc "data"
bun run scripts/upstash-client.ts EXPIRE session:abc 3600
# Or in one command
bun run scripts/upstash-client.ts SET session:abc "data" --ex 3600
# Check TTL
bun run scripts/upstash-client.ts TTL session:abc
# Scan keys matching pattern
bun run scripts/upstash-client.ts SCAN 0 MATCH "user:*" COUNT 100
PING [message]
ECHO <message>
DBSIZE
TIME
INFO [section]
FLUSHDB # Delete all keys in current DB (DANGEROUS)
FLUSHALL # Delete all keys in all DBs (DANGEROUS)
--ex <seconds> # Expire in seconds
--px <ms> # Expire in milliseconds
--exat <ts> # Expire at Unix timestamp (seconds)
--pxat <ts> # Expire at Unix timestamp (ms)
--nx # Only set if key does not exist
--xx # Only set if key exists
--keepttl # Retain existing TTL
--get # Return old value
--nx # Only add new members
--xx # Only update existing members
--gt # Only update if new score > current
--lt # Only update if new score < current
--ch # Return number of changed elements
--withscores # Include scores in output
--byscore # Range by score instead of rank
--bylex # Range by lexicographical order
--rev # Reverse order
--limit off,count # Limit results (e.g., --limit 0,10)
(nil)Before executing any destructive operation (write, modify, or delete), you MUST ask the user for confirmation. This includes:
Write operations:
Modify operations:
Delete operations:
TTL/Rename operations:
Example confirmation prompt:
"I'm about to HSET
user:1with fields{name: "John", email: "john@example.com"}. Proceed?"
If the user indicates they do not want to be asked for confirmation, respect this for all subsequent operations. Indicators include:
Once YOLO mode is activated, proceed with destructive operations without asking, but still inform the user what was done.
Example:
Set
user:1with{name: "John", email: "john@example.com"}- done.
If credentials are missing or invalid, the script will exit with an error message. Ensure the user has configured either:
UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN)--url and --token flagsWeekly Installs
100
Repository
GitHub Stars
228
First Seen
Feb 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykFail
Installed on
codex84
opencode83
gemini-cli82
claude-code79
cursor78
github-copilot74
Azure 升级评估与自动化工具 - 轻松迁移 Functions 计划、托管层级和 SKU
111,700 周安装
GitHub Actions 工作流创建专家 | 自动化 CI/CD 与部署配置指南
151 周安装
Ghidra深度逆向工程分析助手 - 系统化二进制代码深度调查与数据库优化
149 周安装
数据与漏斗分析实战指南:GA4事件跟踪、UTM参数与转化路径优化
151 周安装
GitLab CLI 集成技能:使用 glab 命令行工具自动化 GitLab 任务
149 周安装
Gmail API 技能:Python 自动化邮件管理、搜索和发送指南
150 周安装
Svelte 组件开发指南:Bits UI、Ark UI、Melt UI 组件库与 Web 组件实战
151 周安装