> Documentation index for agents: https://docs.rocketride.ai/llms.txt

# tool_redis

An experimental RocketRide tool node for namespaced key/value utilities in Redis and Valkey: cache entries, temporary app state and explicit counters.

## About Redis

Redis and Valkey are networked data stores supporting key/value operations and expiration. Applications use them for shared caches and short-lived state.

## What it does

This tool-only node attaches to an agent through its Tool control connection, or to a Tools source for direct SDK calls. It has no data lanes. It exposes seven explicit operations; the app or agent decides when to call them. It does not automatically cache answers, maintain conversation history or implement a rate limiter.

## As a tool

Bare tool IDs below are used with `client.tool(token=token, tool=..., node_id='redis_1', input={...})`. Arguments must be an object, including an empty object for a default SCAN. JSON-encoded objects and model argument objects are normalized through the shared helper; malformed JSON, arrays, scalars and null are rejected. Unknown fields and null values for required fields are rejected. Optional fields set to null use the same defaults as omitted fields. `key` means a nonempty logical UTF-8 key; the namespace is always prepended, and the complete key must fit in 256 UTF-8 bytes. Values are strings only. All serialized tool results are capped at 128 KiB using ASCII-escaped JSON size.

| Tool | Inputs | Success result | Redis command / access |
|---|---|---|---|
| `redis_get` | Required `key` | `key`, `found`, `value` (string or null), `ttl_seconds` | GETRANGE + TTL in MULTI/EXEC; read |
| `redis_set` | Required `key`, `value` (up to configured cap, at most 64 KiB UTF-8); optional integer `ttl_seconds` 0–2147483647 and `condition` NX or XX | `key`, `stored`, `requested_ttl_seconds` | SET with EX/NX/XX; write |
| `redis_ttl` | Required `key` | `key`, `exists`, `has_expiry`, `ttl_seconds` | TTL; read |
| `redis_expire` | Required `key`, integer `ttl_seconds` 1–2147483647 | `key`, `updated`, `requested_ttl_seconds` | EXPIRE; write |
| `redis_incr` | Required `key`; optional `amount`, a signed 64-bit decimal string, default `"1"` | `key`, `value_decimal` (string) | INCRBY; write |
| `redis_scan` | Optional unsigned 64-bit decimal string `cursor`, default `"0"`; integer `count` 1–500, default 100 | `cursor`, `keys` (logical names), `skipped` (count), `done` | One SCAN MATCH namespace* COUNT per call; read |
| `redis_delete` | Required `keys`, an array of 1–100 explicit logical keys, matched literally | `deleted_count` | DEL; write |

Every successful result also has `success: true`. Errors have `success: false`, `error_code`, sanitized `error`, and `outcome` (`not_applied` or `unknown`). Codes include invalid_input, invalid_encoding, value_too_large, result_too_large, invalid_operation, permission_denied, authentication_error, connection_error, invalid_host and not_initialized. Missing keys and conditional SET refusal are successful outcomes, not exceptions. Error messages never echo passwords or raw server exceptions. Pool exhaustion is reported as `not_applied`. A connection failure after a mutation may have been sent is reported as `unknown`. No command is automatically retried; inspect state before deciding to retry, especially for INCR.

GET distinguishes an empty string from a missing key. It fetches at most the value cap plus one byte and checks overflow before UTF-8 decoding. Binary, wrong-type, oversized values and oversized serialized results produce explicit errors. TTL is -2 for missing, -1 for persistent, otherwise remaining seconds. These are observations, not promises that a later call sees the same state.

SET defaults to a 3600-second expiry; 0 means persistent. A successful overwrite replaces the previous value and expiry and can replace another Redis data type. NX means only if absent, XX only if present; `stored: false` means the condition skipped the write. EXPIRE accepts positive seconds only; `updated: false` means missing. Reported requested TTL values are intent, not measured remaining lifetime.

INCRBY is atomic, preserves an existing expiry and creates a persistent key if missing. It does not attach an expiry automatically; a separate EXPIRE call is not atomic with INCR. Both input amount and output value use decimal strings to preserve signed 64-bit precision across JavaScript. Wrong types, malformed integers and overflow return errors without changing the value.

SCAN returns the next cursor and the valid keys from one server page. COUNT is a work hint, not a hard key-count limit; pages can be empty before completion, contain duplicates, and vary during concurrent writes. Only cursor `"0"` means finished. The node validates every returned namespace and strips exactly one prefix. It skips foreign, malformed, binary, or oversized keys and reports how many were skipped. Results over 128 KiB return an error. Retrying with a smaller count may help, but is not guaranteed. SCAN can still cause the client to receive a larger server reply before the serialized-result check. Use a dedicated namespace and Redis ACLs; a prefix is not per-user authorization.

## Configuration

Targets standalone Redis 7.0+ or Valkey 7.2+. Cluster, Sentinel, custom CA/mTLS fields, streams, compare-and-set, publish, listeners, dashboard and worker orchestration are outside v1. The engine passes no caller identity to this node, so it cannot promise per-user isolation.

### Host

Use a hostname/IP plus Port (1–65535), or `rediss://host:port` to enable TLS. URL credentials, paths, query strings and fragments are rejected; configure username/password/database in their own fields. Local engines can use localhost or private networks. On hosted/shared engines, TLS is required and every DNS result must be public. DNS is checked initially and for every new connection. Connections use the validated numeric addresses, and the connected peer is checked before the TLS handshake or Redis authentication. The original hostname is restored for TLS certificate and hostname verification. No user-configurable switch bypasses hosted checks. Network egress controls remain recommended.

### Key prefix

Required, 1 to 128 literal ASCII characters from `[A-Za-z0-9:_-]`, ending in `:`. The separator keeps a namespace such as `app:` distinct from `app2:`. Choose an app/environment namespace such as `rr:answer-cache:dev:`. With `rr:demo:` configured, logical `item` means `rr:demo:item`; logical `rr:demo:item` means `rr:demo:rr:demo:item`. No prefix is auto-stripped from input.

### Allow writes

Defaults to false. SET, EXPIRE, INCR and DELETE all enforce this guard, including direct SDK invocation. Read tools remain available. There is no arbitrary command interface or approval workflow in the node.

### Default TTL (seconds)

Defaults to 3600; 0 deliberately creates persistent SET values. Eviction and server persistence are separate deployment choices. INCR does not inherit this default.

### Maximum value bytes

Can reduce the 64 KiB UTF-8 cap; cannot increase it. Serialize structured values as JSON explicitly. SET also checks that GET can return the value within the 128 KiB serialized-result cap, including JSON escaping. Values written outside the node may still exceed that limit.

### Use TLS

Requires certificate and hostname verification against the Python/OpenSSL trust store. No insecure bypass is exposed. For a private CA, set `SSL_CERT_FILE` to a PEM CA bundle in the engine process environment before starting it. Include any other roots the engine needs in that bundle.

A single owned connection pool is reused per node/pipeline: connect timeout 3 seconds, socket timeout 5 seconds, max_connections 10. Timeouts are per socket operation, not a total wall-clock deadline. An exhausted pool fails rather than waiting indefinitely. Startup PING checks connectivity; configuration-only opens install nothing and never connect. Both client and pool are closed on shutdown or failed startup.

## Authentication

Supply an optional Redis ACL username and the password in the secure configuration field, optionally using `${ROCKETRIDE_REDIS_PASSWORD}` as a RocketRide secret reference. The node does not read credential environment variables directly. Resolve secrets through the platform. Test harness environment variables are separate from runtime credential handling.

Grant PING for startup; SELECT (`+select`) when Database is not 0, since redis-py selects that database on every new connection; GETRANGE, TTL, MULTI and EXEC for GET; SCAN for discovery; SET, EXPIRE, INCRBY and DEL only for the mutations the account needs. Restrict key access to the intended namespace and avoid broad administrator permissions. SCAN visibility is not a replacement for server-level access policy. Passwords are excluded from settings repr and sanitized errors.

## Notes

Open `example.pipe` for direct SDK calls or `agent-example.pipe` for a read-only
chat example from the node directory in VS Code. The chat
example uses the `${ROCKETRIDE_GEMINI_KEY}` secret reference. Configure that
secret in the engine environment before running it.

Keep writes disabled for unverified agents. An agent can choose to call a tool
more than once even with client retries disabled, and each successful
`redis_incr` call increments again.

For this experimental release, INCR remains behind the existing `allow_writes`
setting rather than adding an idempotency key or a second write flag. Its tool
description explicitly tells agents to call once and inspect with GET. This is a
warning, not an exactly-once guarantee: applications requiring that guarantee must
control invocation themselves. Unit tests run without a server with
`engine -m pytest test/tool_redis -q --rootdir .` from `nodes/`, using a built engine
with the current node sources and test dependencies installed.

## Upstream docs

- [Redis SCAN](https://redis.io/docs/latest/commands/scan/)
- [Redis INCRBY](https://redis.io/docs/latest/commands/incrby/)
- [Redis EXPIRE](https://redis.io/docs/latest/commands/expire/)
- [Redis SET](https://redis.io/docs/latest/commands/set/)
- [Redis TTL](https://redis.io/docs/latest/commands/ttl/)
- [redis-py connections](https://redis.io/docs/latest/develop/clients/redis-py/connect/)

<!-- ROCKETRIDE:GENERATED:PARAMS START -->
<!-- Generated by nodes:docs-generate. Do not edit by hand. -->

## Schema

| Field | Type | Description | Default |
|---|---|---|---|
| `tool_redis.allow_writes` | `boolean` | **Allow writes**<br/>Enable SET, EXPIRE, INCR and DELETE. Read-only by default; every mutation checks this setting. | `false` |
| `tool_redis.db` | `integer` | **Database**<br/>Standalone logical database index; must exist on the server. | `0` |
| `tool_redis.default_ttl_seconds` | `integer` | **Default TTL (seconds)**<br/>Expiry when SET omits ttl_seconds; 0 means persistent. SET replaces an existing expiry. | `3600` |
| `tool_redis.host` | `string` | **Host**<br/>Redis host reachable from the engine, or rediss://host:port for TLS. Cloud requires TLS and exclusively public addresses; local engines allow localhost. | `"localhost"` |
| `tool_redis.key_prefix` | `string` | **Key prefix**<br/>Required literal app/environment namespace ending in a colon, using letters, digits, colon, underscore or hyphen. Always prepended; not per-user authorization. | `"rr:"` |
| `tool_redis.max_connections` | `integer` | **Maximum connections**<br/>Finite pool size per node/pipeline; exhausted pools return an error rather than waiting indefinitely. | `10` |
| `tool_redis.max_value_bytes` | `integer` | **Maximum value bytes**<br/>UTF-8 payload cap, at most 64 KiB. Serialized results are additionally capped at 128 KiB. | `65536` |
| `tool_redis.password` | `string` | **Password**<br/>Redis password or a RocketRide secret reference. Stored as a secure credential field. | `""` |
| `tool_redis.port` | `integer` | **Port**<br/>Redis endpoint port. | `6379` |
| `tool_redis.socket_connect_timeout` | `number` | **Connect timeout (seconds)**<br/>Maximum time for a connection attempt. | `3` |
| `tool_redis.socket_timeout` | `number` | **Socket timeout (seconds)**<br/>Maximum socket wait per command. No automatic command retries. | `5` |
| `tool_redis.use_tls` | `boolean` | **Use TLS**<br/>Enable TLS with required certificate and hostname verification. | `false` |
| `tool_redis.username` | `string` | **Username**<br/>Optional Redis ACL username. | `""` |

## Dependencies

- `redis` `>=7.1,<8`

## Source

[<svg viewBox="0 0 16 16" width="15" height="15" fill="currentColor" aria-hidden="true" style="vertical-align:-0.15em;margin-right:0.35em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg> View source](https://github.com/rocketride-org/rocketride-server/tree/develop/nodes/src/nodes/tool_redis)
<!-- ROCKETRIDE:GENERATED:PARAMS END -->
