> ## Documentation Index
> Fetch the complete documentation index at: https://ai.easyaf.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Redis

> StackExchange.Redis authenticated task store with native EXPIRE and pub/sub. Specified; not in this repository yet.

> [!WARNING]
>
> `McpEssentials.Redis` is specified and is not in this repository yet.

Low-latency handles, native TTL, and pub/sub for elicitation. Prefer this over [`IDistributedCache`](https://ai.easyaf.dev/mcpessentials/guides/stores/distributed-cache) when the cache is Redis and you need fan-out.

## When to use it

* The host already runs Redis.
* Tasks should vanish with `EXPIRE` / `EXPIREAT` from `DiscardAfter`.
* Several nodes wait on `ElicitAsync` and can subscribe to a Redis channel.

## Intended how-to

1. Add `McpEssentials.Redis` and a `ConnectionMultiplexer`.
2. Keys:

```
mcp:task:{taskId}            HASH or JSON  (full record, including OwnerUserId)
mcp:user:{ownerUserId}:tasks SET           (optional index for admin sweep)
```

3. Register the store as a singleton with the same current-user factory as [Authenticated tasks](https://ai.easyaf.dev/mcpessentials/guides/authenticated-tasks.md).
4. `CreateTaskAsync` uses `SET` with replica wait (`Wait` / `waitReplicas`) so a later get on any node can see the row. Eventually-consistent Redis without wait is not SEP-2663 compliant.
5. Terminal transitions use a Lua script that checks status before writing.

A missing key is not found. Get does not distinguish expiry from isolation.

## Events

```
PUBLISH mcp:task:input {taskId}:{requestId}
```

Subscribers raise `InputResponseReceived`. Payload is task id plus request id.

## TTL

`EXPIREAT` on the task key from `DiscardAfter` (`CreatedAt + 2×TimeToLive`). No sweeper required. Core `SweepExpiredAsync` is a no-op; Redis owns expiry.

See [Stores](https://ai.easyaf.dev/mcpessentials/guides/stores.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.