Add a Redis cache to your project
Create a private Redis cache on Google Memorystore (S to XL, optional HA and TLS) and connect it to a project as REDIS_URL, from the console or an AI tool.
The quickest way: let the deploy create it#
If your code reads REDIS_URL (or another Redis connection variable) and the project has no value for it yet, deploying from an AI tool or uploading in the console creates a size S, Basic cache and connects it before the build starts. Creating it takes about 5 minutes. When this happens and when it doesn't: Databases and caches the code needs.
What you get#
A dedicated Redis 7.2 instance on Google Memorystore, in Taiwan (asia-east1), for one environment.
| Setting | Choices |
|---|---|
| Memory | S 1 GiB, M 2 GiB, L 4 GiB, XL 8 GiB. It can be expanded later, never reduced. |
| Availability | Basic, or High availability with a replica that takes over. Fixed once created. |
| TLS encryption | Off by default. Fixed once created. With TLS, the project also needs the CA certificate. |
| Eviction policy | What happens when memory is full: noeviction, allkeys-lru, allkeys-lfu, allkeys-random, volatile-lru, volatile-lfu, volatile-random or volatile-ttl. Can be changed. |
- Private. The cache has a private address only. Only projects you connect can reach it, and only with the AUTH password, which is always on. You can't reach it from your own computer; from an AI tool,
caches_commandruns single commands for you. - What the plan allows. Free has no caches. Pro allows 5, Team 20, Business by contract, all four sizes.
- Price. Cache prices aren't published yet: the console shows no estimate, and
caches_optionsanswers none. High availability costs more than Basic.
Create a cache#
- Open Caches and select Create cache.
- Enter a Name: lowercase letters, digits and hyphens, starting with a letter, up to 63 characters.
- Choose the Memory, Availability, TLS encryption and Eviction policy. For sessions or data you can't lose, use
noeviction; for a pure cache,allkeys-lru. - Confirm. The cache is ready in about 5 minutes.
Create an Agent Lab Redis cache named sessions, size S, Basic, without TLS, eviction noeviction.The assistant calls caches_create, shows you a preview, and creates it after you agree.
Connect a project#
Connecting writes the connection into the project's secrets and lets the project through the cache's network. Nobody sees the password.
- Open the cache, go to Project connections and select Connect project.
- Choose the project and the variable names, then Preview ENV changes. The preview lists any variables that would be replaced.
- Confirm, and keep Restart project after injection on so the project reads the new values.
Connect my orders-api project to the sessions cache as REDIS_URL.The assistant calls caches_binding_preview, then caches_binding_connect with the preview's token. names maps each variable to a part of the connection:
{ "REDIS_URL": "url", "REDIS_CA": "ca" }Parts are url, host, port, password and ca. A cache with TLS needs ca.
The url part is redis://:<password>@<private address>:6379/0; with TLS it starts with rediss:// and uses the port Memorystore gives a TLS cache (6378). Most clients take it as it is. With TLS, also give the client the CA certificate:
import { createClient } from "redis";
const redis = createClient({
url: process.env.REDIS_URL,
socket: process.env.REDIS_CA ? { tls: true, ca: process.env.REDIS_CA } : undefined,
});
await redis.connect();A cache must be Ready before a project can connect. Disconnect removes the project's access; its credentials are removed once its network access is revoked.
Change or delete a cache#
- Rename, expand memory or change the eviction policy under Manage, or with
caches_update. TLS and availability can't change: create a new cache instead. - Delete cache deletes every key permanently. Project connections are revoked first.
- The cache's Monitoring shows memory, connections, commands, hit rate and evicted keys. Any evicted keys mean the cache is full: a larger size helps.
From an AI tool, caches_update and caches_delete need the cache's current generation from caches_get. caches_command runs one Redis command from an allowlist: reads at once, writes after you confirm. AUTH, CONFIG, EVAL, FLUSH and KEYS are refused. See MCP tools › Redis (caches).