| name | upstash-redis-kv |
| description | Read and write to Upstash Redis-compatible key-value store via REST API. Use when there is a need to save or retrieve key-value data, use Redis features (caching, counters, lists, sets, hashes, sorted sets, etc.) for the current interaction, or when the user explicitly asks to use Upstash or Redis. |
Upstash Redis Key-Value Store
Interact with Upstash's Redis-compatible key-value store using the REST interface.
Script Location
bun run scripts/upstash-client.ts <command> [args...]
IMPORTANT: Always run with bun run, not directly.
Configuration
Environment Variables
The script uses these environment variables by default:
UPSTASH_REDIS_REST_URL - The Upstash REST API URL
UPSTASH_REDIS_REST_TOKEN - The Upstash REST API token
Overriding Credentials
If 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
Command Reference
String Commands
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>
Hash Commands
Hashes store field-value pairs. Pass fields and values as alternating arguments:
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]
Examples:
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
List Commands
Lists are ordered collections. Values are pushed/popped from left (head) or right (tail):
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>
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>
Examples:
bun run scripts/upstash-client.ts RPUSH tasks "task1" "task2" "task3"
bun run scripts/upstash-client.ts LRANGE tasks 0 -1
bun run scripts/upstash-client.ts LPOP tasks
bun run scripts/upstash-client.ts RPOP tasks
Set Commands
Sets store unique, unordered members:
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]
Examples:
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
Sorted Set Commands
Sorted sets store members with scores for ranking:
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]
Examples:
bun run scripts/upstash-client.ts ZADD leaderboard 1000 "player1" 1500 "player2" 1200 "player3"
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"
bun run scripts/upstash-client.ts ZRANGEBYSCORE leaderboard 1000 1500 --withscores
Key Commands
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>
Examples:
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
bun run scripts/upstash-client.ts TTL session:abc
bun run scripts/upstash-client.ts SCAN 0 MATCH "user:*" COUNT 100
Server Commands
PING [message]
ECHO <message>
DBSIZE
TIME
INFO [section]
FLUSHDB
FLUSHALL
Command Options
SET Options
--ex <seconds>
--px <ms>
--exat <ts>
--pxat <ts>
--nx
--xx
--keepttl
--get
ZADD Options
--nx
--xx
--gt
--lt
--ch
ZRANGE Options
--withscores
--byscore
--bylex
--rev
--limit off,count
Output Format
- String values: Printed directly
- null/nil: Prints
(nil)
- Objects/arrays: Pretty-printed as JSON
Confirmation Behaviour
Default: Ask for Confirmation
Before executing any destructive operation (write, modify, or delete), you MUST ask the user for confirmation. This includes:
Write operations:
- SET, SETNX, SETEX, PSETEX, MSET, MSETNX
- HSET, HSETNX
- LPUSH, RPUSH, LPUSHX, RPUSHX, LSET, LINSERT
- SADD
- ZADD
Modify operations:
- INCR, INCRBY, INCRBYFLOAT, DECR, DECRBY
- APPEND, SETRANGE
- HINCRBY, HINCRBYFLOAT
- LREM, LTRIM, LMOVE
- ZINCRBY
Delete operations:
- DEL, UNLINK
- HDEL
- LPOP, RPOP
- SREM, SPOP, SMOVE
- ZREM, ZREMRANGEBYRANK, ZREMRANGEBYSCORE, ZPOPMIN, ZPOPMAX
- FLUSHDB, FLUSHALL (extra caution)
TTL/Rename operations:
- EXPIRE, EXPIREAT, PEXPIRE, PEXPIREAT, PERSIST
- RENAME, RENAMENX
Example confirmation prompt:
"I'm about to HSET user:1 with fields {name: "John", email: "john@example.com"}. Proceed?"
YOLO Mode: Skip Confirmation
If the user indicates they do not want to be asked for confirmation, respect this for all subsequent operations. Indicators include:
- "YOLO mode"
- "Don't ask for confirmation"
- "You're free to make changes without asking"
- "Just do it"
- "No need to confirm"
- "Auto-approve" or "auto-confirm"
- Any similar phrasing indicating blanket approval
Once YOLO mode is activated, proceed with destructive operations without asking, but still inform the user what was done.
Example:
Set user:1 with {name: "John", email: "john@example.com"} - done.
Error Handling
If credentials are missing or invalid, the script will exit with an error message. Ensure the user has configured either:
- Environment variables (
UPSTASH_REDIS_REST_URL, UPSTASH_REDIS_REST_TOKEN)
- Or provides credentials via
--url and --token flags
When to Use This Skill
- User explicitly asks to store or retrieve data from Upstash/Redis
- Need to persist data across conversations or sessions
- Implementing caching for expensive operations
- Maintaining counters, rate limits, or statistics
- Storing user preferences or session data
- Building leaderboards or rankings (sorted sets)
- Managing queues or task lists (lists)
- Tagging or categorisation (sets)
- Storing structured objects (hashes)
- Any scenario requiring fast key-value storage