1---
2title: Redis
3description: Redis in a Project. Bind Railway.ReadRedis / WriteRedis / ReadWriteRedis on a Service.
4---
5
6[`Railway.Redis`](/providers/railway/redis) is a Redis container in
7a [Project](/railway/compute/projects) (`redis:7` or
8`bitnami/redis`). Alchemy writes `REDIS_URL` / `REDISPASSWORD` on
9the service. Bind [`ReadWriteRedis`](/providers/railway/readwriteredis)
10on a [Service](/railway/compute/services). Reach it from a laptop
11through [`TcpProxy`](/railway/networking#tcp-proxies) on port `6379`.
12
13## Create Redis
14
15Pass a Project. Alchemy generates a unique name and password unless
16you pass them. Default image is `redis:7`.
17
18```typescript
19const site = yield* Railway.Project("Site");
20const cache = yield* Railway.Redis("Cache", { project: site });
21```
22
23:::note
24Prefer omitting `name` in tests and CI so names stay unique and
25reclaimable.
26:::
27
28## A stable name
29
30Pass `name` when you want a stable service name. Changing it later
31updates the service in place.
32
33```typescript
34const cache = yield* Railway.Redis("Cache", {
35 project: site,
36 name: "cache",
37});
38```
39
40## Image
41
42Official Redis (`redis:7`) is started with `--requirepass`. Bitnami
43reads `REDIS_PASSWORD`. Updating the image is in place.
44
45```typescript
46const cache = yield* Railway.Redis("Cache", {
47 project: site,
48 image: "bitnami/redis",
49});
50```
51
52## Bind from a Service
53
54Yield `Railway.ReadWriteRedis` (or `ReadRedis` / `WriteRedis`) in
55the Service's constructor. Provide the matching `*Http` layer. Runtime commands
56use `REDIS_URL` (`{name}.railway.internal`).
57
58```typescript
59import * as HttpServerResponse from "effect/http/HttpServerResponse";
60
61const Cache = Railway.Redis("Cache", { project: Site });
62
63export default class Api extends Railway.Service<Api>()(
64 "Api",
65 { project: Site, main: import.meta.url, port: 3000 },
66 Effect.gen(function* () {
67 const cache = yield* Railway.ReadWriteRedis(Cache);
68 return {
69 fetch: Effect.gen(function* () {
70 yield* cache.set("marker", "hello");
71 const value = yield* cache.get("marker");
72 return HttpServerResponse.json({ value });
73 }),
74 };
75 }).pipe(Effect.provide(Railway.ReadWriteRedisHttp)),
76) {}
77```
78
79## Public TCP
80
81Attach a [`TcpProxy`](/railway/networking#tcp-proxies) on `6379` to
82reach Redis from outside the private network.
83
84```typescript
85const cache = yield* Railway.Redis("Cache", { project: site });
86const proxy = yield* Railway.TcpProxy("CacheProxy", {
87 redis: cache,
88 environment: site,
89 applicationPort: 6379,
90});
91```
92
93## Password
94
95Wrap `password` with `Redacted.make(...)`. If omitted, a password is
96generated on first create and kept. Never persisted in attributes.
97
98```typescript
99import * as Redacted from "effect/Redacted";
100
101const cache = yield* Railway.Redis("Cache", {
102 project: site,
103 password: Redacted.make("…"),
104});
105```
106
107## Where next
108
109[Regions](/railway/compute/regions) lists codes.
110[Services](/railway/compute/services) is the container that binds
111`ReadWriteRedis`.
112The [`Redis` reference](/providers/railway/redis) lists every prop.