# A Redis-compatible cache that scales to zero and keeps its keys

Gregale · Updated 2026-12-05

Add a Valkey cache to an app with two commands: private address, REDIS_URL set before the first start, keys kept when it parks. Tested on Gregale, with costs.

**Gregale runs Redis-compatible caches next to your app, and a cache parks when
nothing uses it without losing its keys.** Each cache is
[Valkey](https://valkey.io), the BSD-licensed fork of Redis, in its own
microVM with a private address that only your apps can reach. Every Redis
client library works with it unchanged. Hobby includes one cache, Pro three
and Scale ten, and a cache is billed as compute only while it runs. This page
shows the setup, a production run, what it costs and when another host fits
better.

**[Add a cache to an app](#add-a-cache-to-an-app)** with two commands, then
read [what is kept when it parks](#what-is-kept-and-what-is-not).

## Add a cache to an app

From the app's directory:

```bash
gregale add redis --app my-api
gregale deploy --name my-api
```

`gregale add redis` writes the cache into the app's `gregale.yaml`:

```yaml
caches:
  - cache: my-api-redis
    create: true
```

The deploy creates `my-api-redis` if it does not exist yet and sets
`REDIS_URL` on the app before the first start, so a brand-new app boots with
it. The URL is `redis://my-api-redis.svc.gregale:6379`: no password, because
the cache has no public address and only apps in your account that are bound
to it can connect. `--memory` sets the data size in MB (a multiple of 32, from
32 to 512, or 384 on Hobby, default 128), `--eviction-policy` what happens
when it is full (default `allkeys-lru`; `noeviction` refuses writes instead)
and `--idle-timeout` how long it stays up with no traffic (300 to 86,400
seconds, default 900).

The app reads `REDIS_URL` like any Redis URL. Turn on your client's retries:
a resize or a Valkey update closes open connections, and the retry reconnects
without failing the request. The test app below is FastAPI with redis-py:

```python
import os, time
import redis
from redis.backoff import ExponentialBackoff
from redis.retry import Retry
from fastapi import FastAPI

app = FastAPI()
r = redis.Redis.from_url(
    os.environ["REDIS_URL"],
    decode_responses=True,
    retry=Retry(ExponentialBackoff(), 3),
    retry_on_error=[redis.ConnectionError, redis.TimeoutError],
)


@app.get("/")
def hits():
    start = time.perf_counter()
    n = r.incr("hits")
    return {"hits": n, "redis_ms": round((time.perf_counter() - start) * 1000, 2)}
```

To bind a cache to an app by hand instead, run
`gregale redis create sessions` and `gregale redis bind sessions --app my-api`.
A Docker Compose project that has a `redis` or `valkey` service gets a cache
named `<project>-<service>`, and the services that pointed at it get its
address in the form they used.

## Verified on Gregale, December 5, 2026

The test deployed the app above, at first without the retry settings, with
`gregale add redis --idle-timeout 300`, so the cache parks after 5 minutes
without traffic.

- **Deploy.** The plan line read
  `redis: redis-cache-test-redis as REDIS_URL (created at 128 MB if missing)`.
  The deploy created the cache, bound it, built the image (the build command
  took 14.9 seconds) and returned after 53 seconds.
- **Round trip.** While the app was running, an `INCR` from the app to the
  cache took 1.4 to 2.1 ms, measured inside the app. The whole request took
  0.48 to 0.57 seconds to its first byte from a laptop across the Atlantic, of
  which about 0.32 seconds was TCP and TLS setup.
- **From a terminal.** `gregale redis exec redis-cache-test-redis GET hits`
  printed `"26"`, and `TTL session:alice` printed `(integer) 3596`. The
  command runs from a short task inside the bound app, because the cache has
  no public address.
- **Park and wake.** Six minutes after the last request, the cache had
  parked (`gregale app instances` showed no instances) and the app was frozen.
  The next request woke both. Its `INCR` returned 27, so the counter had kept
  its value, and took 250 ms on the app's existing pooled connection: the time
  to wake the cache. The response carried `x-faas-wake: restored`, and its
  first byte arrived after 1.09 seconds, against 0.48 seconds while both were
  running. Afterwards `TTL session:alice` read 3146, which is what the wall
  clock predicted: the time parked counted against the TTL.
- **Resize.** `gregale redis resize redis-cache-test-redis --memory 160` went
  live about 35 seconds later, with the counter and the TTL intact. The switch
  closed the app's pooled connection. redis-py does not retry by default, so
  the first request after it failed with `ConnectionResetError` (a 500), and
  the next one reconnected. With the retry settings above, two more resizes
  under steady traffic (192 MB, then 224 MB) failed no request on a closed
  connection, but writes waited while the new VM took over. One `INCR` waited
  more than 20 seconds; in the other run one waited 30 seconds, until the app's
  request time limit answered 503. Both increments landed, and the counter
  never skipped or lost a value. Resize when traffic is quiet.

`gregale redis get` shows the cache's settings, what it would cost if it never
parked, and its latest usage sample:

```text
Memory:    128 MB
Eviction:  allkeys-lru
Idle park: 300s
Billed:    208 MB VM while running (about 154 GB-h a month if it never parks)
Bound to:  redis-cache-test
Used:      899.6 KiB of 128.0 MiB (0.7%)
Evicted:   0 keys since start
Clients:   1
```

## What is kept and what is not

A cache is a cache: it has no disk persistence and no replica.

| Event                                                   | Keys                                                                                                                                      |
| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| The cache parks when idle, then wakes                   | Kept: its memory is saved with it                                                                                                         |
| `gregale redis restart`                                 | Kept: memory saved and restored                                                                                                           |
| `gregale redis resize` or `update` (new Valkey release) | Kept: a new VM copies the cache before it takes over; writes wait during the switch and open connections close, so turn on client retries |
| The cache crashes or its machine fails                  | Lost: it starts empty                                                                                                                     |

Keys whose TTL passes while the cache is parked are expired when it wakes, so
parking does not stretch a TTL. Keep data you cannot lose in
[managed PostgreSQL](https://gregale.dev/docs/postgres.md) or [object storage](https://gregale.dev/docs/object-storage.md),
and use the cache for sessions, rate-limit counters, computed results and job
queues you can rebuild.

While the cache is parked, the platform keeps your app's client connections
open. The next command wakes it and waits, so the client sees one slow reply
instead of a dropped connection. `PING` and other commands that read no data
do not keep a cache awake, so a pooled client that pings its connections does
not stop it from parking. A connection that is subscribed to a channel or
waiting in a blocking command such as `BLPOP` does keep it awake.

## What it costs

A running cache is billed like an app: its VM's memory plus 8 MB for every
second it runs, against your plan's included GB-RAM-hours. The VM is the
cache's size plus 64 MB plus an eighth of the size, which keeps memory
fragmentation from taking the cache down. A parked cache costs only snapshot
storage.

| Cache size | VM while running | GB-RAM-hours a month if it never parks |
| ---------: | ---------------: | -------------------------------------: |
|      32 MB |           100 MB |                               about 77 |
|     128 MB |           208 MB |                              about 154 |
|     256 MB |           352 MB |                              about 257 |

Hobby costs $10 a month and includes 200 GB-RAM-hours for apps and caches
together, so a 128 MB cache that never parks would use most of it. Usage past
the allowance costs $0.05 per GB-RAM-hour, up to your spend cap. A cache that
works during office hours and parks at night uses a fraction of that: about 37
GB-RAM-hours for a 128 MB cache running 8 hours on each of 22 working days.
Keep the idle timeout short unless the first command after a quiet period must
be fast.

## How other hosts sell Redis

Checked on each host's own pages on December 5, 2026:

| Host                        | Smallest paid option                                                                                    | Free option                         |
| --------------------------- | ------------------------------------------------------------------------------------------------------- | ----------------------------------- |
| Render Key Value            | $10 a month for 256 MB, Valkey 8, saved to disk                                                         | 25 MB, nothing saved to disk        |
| Heroku Key-Value Store      | Mini, up to $3 a month for 25 MB, nothing saved to disk; Premium 0 up to $15 for 50 MB with persistence | None                                |
| Upstash Redis               | $0.20 per 100,000 commands plus $0.25 per GB stored, or a fixed 250 MB for $10 a month                  | 250 MB and 500,000 commands a month |
| Railway                     | The Redis image as a service, billed by usage at $10 per GB of memory a month                           | Free plan at $0 a month             |
| DigitalOcean Managed Valkey | $15 a month for 1 GiB                                                                                   | None                                |
| Gregale                     | Included in Hobby ($10 a month, one cache up to 384 MB), billed as compute while it runs                | None: caches start at Hobby         |

Fly.io offers Upstash Redis through `flyctl redis create`, at Upstash's prices.

**Choose another host when:**

- **The data must survive a crash.** Render's paid instances and Heroku's
  Premium plans write to disk; a Gregale cache does not.
- **You need more than 512 MB, replicas or several regions.** Gregale caches
  stop at 512 MB, run as one instance and live in one region.
- **Something outside your account must connect.** A Gregale cache has no
  public address; `gregale redis exec` is the way in from a terminal. Upstash
  is reachable from anywhere over TLS or HTTP.
- **You are on a free plan.** Render, Upstash and Fly's Upstash all have free
  tiers; Gregale caches start at Hobby.

## Limits

- Commands that change the server are refused: `CONFIG`, `DEBUG`, `MODULE`,
  `SHUTDOWN`, `SAVE`, `BGSAVE`, `BGREWRITEAOF`, `REPLICAOF`, `SLAVEOF`,
  `FAILOVER`, `CLUSTER`, `ACL`, `MONITOR`, `SYNC`, `PSYNC`, `REPLCONF` and
  `MIGRATE`. Lua scripts, functions, pub/sub, streams and transactions work.
- A cache has no password and no per-app permissions. Any app that may
  connect can read and delete every key, so put data one app must not see in
  a separate cache and bind only the apps that need it.
- Shrinking a cache needs `--evict`, even when its data fits the smaller
  size; growing it does not.
- `gregale redis exec` sends one command per call and refuses commands that
  stream, such as `SUBSCRIBE`.
- Alerts can fire at 90% memory use (`cache_memory_high`), on evicted keys, or
  when a cache comes back empty (`cache_reset`).

## Sources

Gregale facts come from the production run above and the `gregale redis` and
`gregale add redis` command help in CLI rc.396. Other hosts, checked December
5, 2026:
[Render pricing](https://render.com/pricing),
[Render Key Value](https://render.com/docs/key-value),
[Heroku Key-Value Store](https://devcenter.heroku.com/articles/heroku-redis),
[Upstash Redis pricing](https://upstash.com/pricing/redis),
[Railway pricing](https://docs.railway.com/reference/pricing/plans),
[DigitalOcean managed database pricing](https://www.digitalocean.com/pricing/managed-databases),
[Upstash Redis on Fly.io](https://fly.io/docs/upstash/redis/).

## Questions

### Is a Gregale cache real Redis?

It is Valkey, the BSD-licensed fork of Redis, so Redis client libraries and Redis commands work unchanged. Lua scripts, pub/sub, streams and transactions work; commands that change the server, such as CONFIG, SAVE and REPLICAOF, are refused.

### Does the cache keep its data when it scales to zero?

Yes. A cache that parks saves its memory with it, and the keys are back when the next command wakes it. A restart, a resize and a Valkey update keep the data too. A crash or a machine failure loses it, because a cache has no disk persistence or replica.

### How much does a Redis cache cost on Gregale?

A running cache is billed like an app, by its VM memory plus 8 MB per running second, against your plan’s GB-RAM-hours. A 128 MB cache runs in a 208 MB VM, about 154 GB-RAM-hours a month if it never parks; Hobby includes 200 for $10 a month. A parked cache costs only snapshot storage.

### Can I connect to the cache from my laptop?

Not directly: a cache has no public address, only a private one your bound apps reach. gregale redis exec sends one command from a short task inside a bound app and prints the reply, for example gregale redis exec my-cache GET hits.

### Which Gregale plans include a cache?

Hobby includes one cache of up to 384 MB, Pro three and Scale ten of up to 512 MB each. Free has none. Caches have their own limit and do not use any of the plan’s app slots.

Canonical URL: https://gregale.dev/articles/redis-compatible-cache-scale-to-zero

