# Set up the Redis object cache with Codex

> Setting up a Redis object cache with Codex means asking it in your terminal to check a site's object cache, test the Redis connection and enable it through xSpeed Hub.

Page: https://xspeedcache.com/agent/codex/object-cache/
Last updated: October 2026

You are in a Codex session in a terminal, probably with the site's repository open. Type: set up Redis for the shop site, test before you enable. Codex calls get_object_cache_status through xSpeed Hub, which reports whether the drop-in is installed, which backend is configured and its stats. That does not prove Redis is reachable, so Codex has to follow it with test_object_cache, where the site's plugin connects to the Redis server and reads and writes a probe value.

A failed test returns the server's own error, and a pass is your cue to let Codex call toggle_object_cache with enabled set to true. Enabling installs the object-cache.php drop-in. Run it only after a passing test. The site tests again when you enable and stops with Could not enable if Redis is unreachable, but the probe gives you the server's exact reason first. Codex can then read the status again to confirm that the drop-in is in place and the backend is connected.

The difference for Codex is where the control lives. The sandbox and approval policy govern shell commands, while MCP tools have their own settings: default_tools_approval_mode for the server and approval_mode for each tool. Codex prompts by default only for MCP calls that advertise side effects, and the Hub's tools declare none, so set the xspeedhub server to prompt and give the two reads approve. If the session is on the server you can ask it to run redis-cli ping too, but the sandbox limits what that command can reach. A ping from a laptop shell checks the wrong machine: the test_object_cache result comes from the site's own server, which is the one that matters.

## Set up Codex once

### 1. Put your sites in xSpeed Hub

Sign in at app.xspeedcache.com with Google or email; the Hub is free and has no site cap. Then connect each WordPress site from its own dashboard: click Connect Hub in the xSpeed Cache top bar, then Connect via xSpeed Hub. Each site needs the free xSpeed Cache plugin.

### 2. Add xSpeed Hub and sign in

Add the server with its URL, then log in. The login opens an xSpeed Hub page in your browser; approve access there. There is no token to paste, and Codex keeps the credentials it receives. Start Codex and type /mcp to see the server.

```bash
codex mcp add xspeedhub --url https://app.xspeedcache.com/xspeed/mcp
codex mcp login xspeedhub
```

### 3. Keep the Hub's tools on a prompt

Open ~/.codex/config.toml. Set the server to prompt for every tool, then let one read tool run without a question. The tool timeout defaults to 60 seconds, and a PageSpeed test can take up to about two minutes, so raise it.

File: `~/.codex/config.toml`

```toml
[mcp_servers.xspeedhub]
url = "https://app.xspeedcache.com/xspeed/mcp"
default_tools_approval_mode = "prompt"
tool_timeout_sec = 150

[mcp_servers.xspeedhub.tools.get_cache_status]
approval_mode = "approve"
```

Full setup: https://xspeedcache.com/agent/codex/

### Before you send a prompt that changes something

Reads change nothing on your sites, though contact_support emails xSpeed support. Writes run once your connection allows them, so your client's approval prompt and a read-only connection (the token's Read-only everywhere switch, or a Viewer sign-in) are the gates that matter. Codex has two layers for shell work: the sandbox mode limits what commands can touch, and the approval policy sets when Codex stops to ask. MCP tools have their own settings. Each server takes default_tools_approval_mode (auto, prompt, writes or approve) and each tool can override it with approval_mode. Codex also asks about MCP calls that advertise side effects or a destructive annotation, but xSpeed Hub's tool definitions do not declare either, so do not rely on that default for the Hub; set the server to prompt. approval_policy never, --yolo and an auto_review reviewer take the human out of the loop. xSpeed Hub has no confirmation step of its own, so an approved or auto-approved write runs as soon as your connection allows writes.

## Prompts

- Use xSpeed Hub to run get_object_cache_status and test_object_cache on shop, then summarise whether Redis is ready.
- This session is on the web server. Run redis-cli ping, then ask xSpeed Hub for test_object_cache on blog, and tell me if both agree.
- With xSpeed Hub, enable the object cache on shop only if the Redis test passes, and read the status back afterwards.

## Example session

```
You: Use xSpeed Hub to set up Redis for shop. Test before you enable.
  → get_object_cache_status(site: shop) [read-only]: Drop-in not installed. Backend: Redis configured.
  → test_object_cache(site: shop) [read-only]: Connected. Probe value written and read back.
Agent: Test passed. I will call toggle_object_cache with enabled: true on shop. Proceed?
You: Proceed.
  → toggle_object_cache(site: shop, enabled: true) [changes site]: Drop-in installed. Redis active.
  → get_object_cache_status(site: shop) [read-only]: Drop-in installed. Backend: Redis, connected.
Agent: Redis is the object cache for shop and the status confirms the drop-in.
```

## How it works

1. **Read the current state**: get_object_cache_status reports whether the object-cache.php drop-in is installed, which backend is configured, Redis or Memcached, and its stats. It does not prove the server answers, so a clean status is not a green light.
2. **Test the connection first**: test_object_cache opens a live connection to the configured server and does a read and write probe with the settings saved on the site. A failure comes back with the server's own reason, such as a wrong password, a refused connection or a permission error. The Hub tells the agent to run this before toggle_object_cache.
3. **Fix the connection if the test fails**: get_settings reads the object-cache module, with secrets masked. update_settings changes it, for example the host or port. On a managed host that defines these values in wp-config.php, the fields are read-only and a write that tries to change one is refused with the name of the constant. For a host that wants the constants pasted, get_object_cache_status with detail set to snippet returns the wp-config.php block.
4. **Turn it on**: toggle_object_cache with enabled true makes the site test the connection again, write the connection constants into wp-config.php and install the object-cache.php drop-in. If the test fails, it stops with "Could not enable" and writes nothing. If wp-config.php is not writable, the drop-in goes in and the reply tells you to add the snippet by hand. The Hub tells the agent to briefly confirm intent first.
5. **Check it took**: The drop-in loads on the next request, so the agent reads get_object_cache_status again after a page load and runs test_object_cache once more. The status also warns when the cache connects but refuses writes, so a connected cache that stores nothing does not pass as healthy.
6. **Flush when stale data survives**: flush_object_cache empties the persistent object cache. Use it when old options, transients or query results outlive a page cache purge. It does not touch the page cache; purge_cache does that.

## Reference

| | |
| --- | --- |
| Read tools | get_object_cache_status and test_object_cache, both work on a read-only connection |
| Write tools | toggle_object_cache (enabled true or false) and flush_object_cache |
| Backends | Redis or Memcached |
| Status detail | status (default) or snippet, the wp-config.php constants block |
| What status proves | Drop-in installed, backend configured, stats. Not that the server is reachable |
| What the test proves | A live connect and a read and write probe on the saved settings, with the server's own error on failure |
| Enable does | Tests the connection, writes connection constants to wp-config.php, installs the object-cache.php drop-in |
| Disable does | Removes xSpeed's drop-in and its wp-config.php block; a drop-in owned by another plugin is left alone |
| Connection timeout | 1 second by default, set in the object-cache module |
| Settings module | object-cache, for get_settings and update_settings |
| Every site at once | None of these tools accept site: "all"; one site per call |
| Confirmation | None on the Hub; your client's prompt is the gate |

## Rules

- Test before you toggle. The Hub tells the agent to run test_object_cache first, because a cache server that does not answer slows every request while the page cache still looks healthy.
- Keep the Redis password out of the chat. get_settings masks it, but the wp-config.php snippet is built from the saved settings and can include a saved password. Set secrets in wp-config.php or in the xSpeed panel.
- toggle_object_cache and flush_object_cache are write tools. The Hub tells the agent to briefly confirm intent for the object-cache toggles, but that is guidance, not a lock. Your client's approval prompt and a read-only grant are the gates that matter. A read-only grant means the connection token with Read-only everywhere on, or a Viewer member's sign-in; an OAuth sign-in gets the scopes the client asks for, which are read and write by default.
- If another plugin owns the object-cache.php drop-in, turn its object cache off in that plugin. xSpeed leaves a drop-in it did not install in place when you disable.
- A flush clears cached data, so the next requests rebuild it from the database and the site is briefly slower. Flush one site, then check it, before you repeat it.

## Good to know with Codex

Codex does not prompt for Hub tools by default, because the Hub declares no read-only or destructive annotation. Until you set default_tools_approval_mode to prompt for the xspeedhub server, toggle_object_cache can run as soon as Codex calls it. approval_policy never, --yolo and an auto_review reviewer also take you out of the loop. While you are only diagnosing, use the connection token with Read-only everywhere on, or sign in as a Viewer member, because then the Hub refuses every write.

## More prompts for this job

They work in any client connected to xSpeed Hub.

- Using xSpeed Hub, is a persistent object cache running on shop, and which backend does it use?
- Use xSpeed Hub to test whether Redis is reachable from shop. Do not change anything.
- Shop is slow in wp-admin. Use xSpeed Hub to check the object cache before anything else.
- With xSpeed Hub, test Redis on shop, and if it passes, turn the object cache on.
- Ask xSpeed Hub for the wp-config.php object cache snippet for docs.
- Use xSpeed Hub to flush the object cache on blog. Old options survive a page cache purge.
- With xSpeed Hub, turn the object cache off on shop and confirm the drop-in is gone.

## Frequently asked questions

### Should I use redis-cli from Codex or the xSpeed test?

Use the xSpeed test as the deciding check. The test_object_cache tool runs from the site's own server with the connection settings the plugin uses. A redis-cli ping from Codex is a second opinion, and only when the session is on that server and its sandbox lets the command reach Redis.

### Does Codex stop before it toggles the object cache?

Only if you set it up that way. Codex prompts by default for MCP calls that advertise side effects, and the Hub declares none, so set default_tools_approval_mode to prompt for the server and you approve the toggle yourself. With approval_policy never, the yolo flag, an auto-approving reviewer or a per-tool approve setting, the Hub runs the write as soon as your connection allows writes, because the Hub has no confirmation step of its own.

### Why test the connection before turning the object cache on?

Because a cache server that does not answer costs time on every request while the page cache still looks fine. The Hub tells the agent to run test_object_cache first, and the site also tests the connection when you enable and refuses to continue if it fails. The probe is still worth running on its own, since it returns the server's exact reason, such as a wrong password or a refused connection.

### What happens if Redis stops answering after I enabled it?

The site keeps working. The drop-in is built never to take the site down: it falls back to WordPress's own cache for the length of the request and marks itself as degraded. A request can still wait up to the connection timeout, which is 1 second by default, so the site gets slower. xSpeed reports that state as degraded, and test_object_cache names the fault.

### Can the agent install Redis for me?

No. These tools connect xSpeed to a Redis or Memcached server that already exists and switch the object cache on or off. Getting a server is a hosting task. xSpeed uses the phpredis extension when it is there and its own built-in client when it is not.

### What is the difference between flush_object_cache and purge_cache?

flush_object_cache empties the persistent object cache and nothing else. purge_cache with type object does the same job through the purge tool, and purge_cache with type all also clears the page cache and, when connected, the Cloudflare edge. Use the flush when stale options or transients survive a page cache purge.

### Is the wp-config.php snippet safe to share?

Treat it like a secret. The snippet is built from the settings saved on the site, so it can contain the Redis password if one is saved. Paste it into wp-config.php yourself and avoid sharing it in a chat or a ticket.

## Set up Redis object cache with other agents

[Claude Code](https://xspeedcache.com/agent/claude-code/object-cache/) · [Claude](https://xspeedcache.com/agent/claude/object-cache/) · [Claude Cowork](https://xspeedcache.com/agent/claude-cowork/object-cache/) · [ChatGPT](https://xspeedcache.com/agent/chatgpt/object-cache/) · [Cursor](https://xspeedcache.com/agent/cursor/object-cache/) · [GitHub Copilot in VS Code](https://xspeedcache.com/agent/github-copilot/object-cache/) · [Windsurf](https://xspeedcache.com/agent/windsurf/object-cache/) · [Gemini CLI](https://xspeedcache.com/agent/gemini-cli/object-cache/) · [Antigravity](https://xspeedcache.com/agent/antigravity/object-cache/) · [Zed](https://xspeedcache.com/agent/zed/object-cache/) · [Kiro](https://xspeedcache.com/agent/kiro/object-cache/) · [OpenCode](https://xspeedcache.com/agent/opencode/object-cache/) · [OpenClaw](https://xspeedcache.com/agent/openclaw/object-cache/) · [Hermes Agent](https://xspeedcache.com/agent/hermes-agent/object-cache/) · [Grok Build](https://xspeedcache.com/agent/grok-build/object-cache/) · [ChatGPT dots](https://xspeedcache.com/agent/chatgpt-dots/object-cache/) · [Grok](https://xspeedcache.com/agent/grok/object-cache/) · [Grok Bot](https://xspeedcache.com/agent/grok-bot/object-cache/) · [Muse](https://xspeedcache.com/agent/muse/object-cache/) · [Manus](https://xspeedcache.com/agent/manus/object-cache/) · [Kimi Code](https://xspeedcache.com/agent/kimi/object-cache/) · [Paperclip](https://xspeedcache.com/agent/paperclip/object-cache/) · [NanoClaw](https://xspeedcache.com/agent/nanoclaw/object-cache/)

## More with Codex

- [Purge the WordPress cache with Codex](https://xspeedcache.com/agent/codex/purge-cache/)
- [Find out why WordPress pages are not cached with Codex](https://xspeedcache.com/agent/codex/troubleshoot-cache/)
- [Scan a website for speed problems with Codex](https://xspeedcache.com/agent/codex/speed-scan/)
- [Run and track PageSpeed tests with Codex](https://xspeedcache.com/agent/codex/pagespeed-tests/)
- [Raise a WordPress site's PageSpeed score with Codex](https://xspeedcache.com/agent/codex/optimize-site/)
- [Tune WordPress cache settings with Codex](https://xspeedcache.com/agent/codex/cache-settings/)
- [Warm the WordPress cache with Codex](https://xspeedcache.com/agent/codex/preload-cache/)
- [Manage Cloudflare caching with Codex](https://xspeedcache.com/agent/codex/cloudflare/)
- [Manage every WordPress site at once with Codex](https://xspeedcache.com/agent/codex/fleet/)

## Documentation

- How to enable Redis or Memcached: https://xspeedcache.com/docs/object-cache/
- How to enable Page Cache: https://xspeedcache.com/docs/page-cache/
- Common problems and troubleshooting: https://xspeedcache.com/docs/common-problems-and-troubleshooting/
