# Upstash Redis MCP

> Upstash connects your serverless Redis database directly into any AI agent, letting you manage complex data structures and caching layers using plain conversation. You can run read/write operations—like fetching user sessions, incrementing counters, or managing message queues—without ever touching a command line or dedicated terminal client.

## Overview
- **Category:** loved-by-devs
- **Price:** Free
- **Tags:** redis, serverless, key-value-store, caching, data-structures, rest-api

## Description

Connecting your Upstash Redis data store to an AI agent means treating it like an extension of your own memory. Instead of having to jump between chat interfaces and a separate database console, you simply ask your agent to perform actions on the cached data.

Your agent handles all the necessary complexity. You can tell it to check if a key exists, retrieve all fields from a user's session hash, or push messages onto a list for background processing. If you need to run multiple commands at once, like checking three different keys and then deleting one, your agent sequences them for you. It’s about making the database an active participant in your workflow. This MCP is available across Vinkius, giving you access to this Redis power from any compatible client.

This functionality takes data management out of the terminal and right into the flow of natural conversation.

## Tools

### decr
Decrements a numeric value associated with a key, useful for tracking limited resources or decreasing counts.

### del
Removes an entire key from the database; be careful because this action cannot be undone.

### exists
Quickly checks whether or not a specific data key is present in your Upstash Redis instance.

### expire
Sets an automatic deletion timer (TTL) on a key, ensuring temporary data cleans itself up later.

### get
Retrieves the simple string value associated with a given key name.

### hget
Pulls out one specific field's value from a structured hash record.

### hgetall
Retrieves every single field and its value contained within a full hash structure.

### hset
Adds or updates specific fields and values inside an existing structured hash key.

### incr
Increases a numeric counter value by one, useful for simple counting mechanisms.

### list_keys
Lists keys in the database based on patterns or prefixes to help you audit what data exists.

### llen
Returns a count of how many elements are currently stored within a specific Redis list.

### lpush
Adds new values to the beginning (left side) of a message queue list.

### lrange
Retrieves elements from a specific range within an ordered Redis list.

### pipeline
Executes many different database commands simultaneously in one call, improving efficiency for batch tasks.

### publish
Sends a message out to all listening subscribers on a specific channel, triggering event logic.

### rpush
Adds new values to the end (right side) of a message queue list.

### sadd
Adds one or more unique items to a set, automatically ignoring any duplicates.

### set
Writes a new value to a key and optionally sets an automatic expiration time.

### sismember
Checks quickly if a unique member ID is already part of a specific set.

### smembers
Retrieves every single unique member ID that belongs to a given set.

### srem
Removes one or more specified members from a unique collection set.

### ttl
Checks how many seconds are left until a key automatically deletes itself.

### key_type
Identifies and reports the underlying data type of a given key (e.g., hash, list, string).

## Prompt Examples

**Prompt:** 
```
Check if my Upstash Redis database is responding.
```

**Response:** 
```
Connection verified! The database responded with PONG. Your Upstash Redis instance is healthy and accepting commands.
```

**Prompt:** 
```
Set a feature flag called 'dark_mode' to true for user 'user123' with a 1 hour expiry.
```

**Response:** 
```
Done! I've set the key `dark_mode:user123` to `true` with a 3600-second (1 hour) expiry. The flag will automatically expire after that time.
```

**Prompt:** 
```
Show me all keys matching the pattern 'session:*' and check their data types.
```

**Response:** 
```
I found 5 keys matching 'session:*'. Checking their types: `session:abc` is a hash, `session:def` is a hash, `session:ghi` is a string, `session:jkl` is a set, and `session:mno` is a list. Most sessions are stored as hashes (field-value pairs for user data).
```

## Capabilities

### Manage Key-Value Pairs
Set a value for a specific key or retrieve that value using simple read/write commands.

### Handle Structured Data Sets
Store and access collections of related data, like user attributes or feature flags, within complex hash structures.

### Process Message Queues
Use lists to add items to the end of a queue (right) or process them from the beginning (left), mimicking stack and queue behavior.

### Track Unique Memberships
Maintain unique collections of identifiers, such as user IDs who have signed up for an event, ensuring no duplicates are stored.

### Monitor Database Health and State
Check if a key exists, see how long it has until expiration (TTL), or determine its data type.

### Execute Batch Operations
Run multiple distinct commands—like getting three different values and then incrementing a counter—in a single request.

## Use Cases

### Debugging a broken user session
A full-stack developer notices user data is corrupted. They ask their agent to use `hgetall` on the relevant session key and then run `key_type` to confirm the structure, instantly pinpointing if it's stored incorrectly.

### Implementing a simple message queue
An operations engineer needs background processing. They use `rpush` to add tasks to a queue list and then have their agent process them using `lrange` or `pop`, completely bypassing the need for dedicated worker services.

### Tracking feature flag rollout
A backend developer wants to test new features on specific users. They use `set` to write a unique key like 'feature:v2:user123' and then set a short TTL using `expire`, guaranteeing the flag expires after testing.

### Building an event notification system
A team needs multiple services to react when user data changes. They use `publish` on a central channel, allowing any listening service (like logging or email) to automatically respond without direct coupling.

## Benefits

- You avoid complex data flow by using `sadd` or `smembers`. Instead of writing code to maintain unique user lists, you simply ask your agent to manage the set membership.
- Rate limiting becomes trivial. You can use `incr` and `decr` in conversational prompts to track usage counts instantly, making it easier to enforce business logic without adding boilerplate code.
- Auditing data structure health is fast. Use `list_keys` or `key_type` to see what keys exist and confirm they are stored as the expected hash format when debugging a session problem.
- Batch operations are simplified with the `pipeline` tool. Instead of sending five separate requests, you ask your agent to run them all at once for maximum efficiency.
- Data lifecycle management is automatic. Setting an expiration using `expire` ensures that temporary keys—like shopping cart states—are deleted without manual cleanup tasks.

## How It Works

The bottom line is that you treat your serverless Redis cache like an active, conversational source of truth for your entire application stack.

1. You connect your Upstash credentials (URL and Token) to the MCP within Vinkius.
2. Your AI agent interprets your natural language request, determining which Redis data operation is needed (e.g., 'get' or 'hset').
3. The MCP executes the command against your live database and returns the resulting data directly to your chat interface.

## Frequently Asked Questions

**How do I check if a key exists using Upstash Redis MCP?**
You use the 'exists' tool to quickly confirm key presence without retrieving any value. This is great for pre-checking data before attempting a read or write operation.

**Can I run multiple commands at once with Upstash Redis MCP?**
Yes, you use the 'pipeline' tool to execute several commands in one request. This saves time and is essential for efficient batch updates across your data structure.

**What is the difference between `incr` and `set` with Upstash Redis MCP?**
`incr` automatically increases a numeric counter by one, ensuring atomic counting. The 'set' tool simply writes a new value or overwrites an existing string value.

**How do I delete data safely using Upstash Redis MCP?**
Use the 'del' tool to remove keys entirely. However, remember that this action is irreversible, so always confirm which key you are deleting first.

**Does Upstash Redis MCP support message queuing?**
Yes, it supports queue patterns using lists. You can add items with 'rpush' and then process them by retrieving ranges or popping the elements out of the list.