---
title: Redis
description: Create a Redis database for caching, queues and sessions, and choose its memory, eviction policy and persistence.
section: Data
order: 3
---

Dekka runs Redis 7.4 or 8.0 in your project's region for caching, queues and sessions. Like PostgreSQL, it's private, so only services you connect to it can reach it unless you turn on its TCP proxy.

## Create a Redis database

On the canvas, choose **Add**, then **Redis**. Pick a name, a **Version** and a **Memory limit**, choose what happens **When memory is full**, and choose **Create Redis**. A new database has 64 MiB unless you choose otherwise.

Redis memory across your organisation counts against one allowance: 64 MiB on Free, 512 MiB on Starter and 2 GiB on Growth. Dekka measures it every hour as `redis_gb_hours`, and each plan includes its allowance for a 730-hour month.

## Connect a service

Drag from a service to the Redis database. The service receives `REDIS_URL` in the form `rediss://default:<password>@<host>:6379`, which uses TLS, and restarts to pick it up.

```ts title="cache.ts"
import { createClient } from "redis";

export const redis = createClient({ url: process.env.REDIS_URL });
await redis.connect();
```

## What happens when memory is full?

The memory limit is Redis's `maxmemory`, and the eviction policy decides what Redis does once it's reached. The default refuses new writes, which suits queues and anything you can't afford to lose. For a cache, evicting least recently used keys is the usual choice.

| In the dashboard | `eviction_policy` |
| --- | --- |
| Refuse writes when full | `noeviction` (default) |
| Evict least recently used keys | `allkeys-lru` |
| Evict least frequently used keys | `allkeys-lfu` |
| Evict least recently used keys with a TTL | `volatile-lru` |
| Evict keys closest to expiry | `volatile-ttl` |
| Evict random keys | `allkeys-random` |

The API also accepts `volatile-lfu` and `volatile-random`.

## Turn persistence on or off

**Persistence** is on by default and writes every change to disk with Redis's append-only file, so data survives a restart. A pure cache can turn it off.

## Browse keys

Select the Redis database and open **Data**. **Keys** lists keys matching a pattern such as `session:*`, with each key's type, time to live and the start of its value. Under **Credentials**, **Rotate** gives every connected service a new password and restarts it.

## Connect from your own machine

Turn on **Public TCP proxy** in the database's settings to give it a public host and port. [TCP proxy](/docs/tcp-proxy) shows how to connect with `redis-cli`.

> [!NOTE]
> Dekka doesn't back up Redis. If what's in Redis matters beyond a restart, keep persistence on and treat Redis as a copy of data that lives somewhere else.
