Redis
Railway.Redis is a Redis container in
a Project (redis:7 or
bitnami/redis). Alchemy writes REDIS_URL / REDISPASSWORD on
the service. Bind ReadWriteRedis
on a Service. Reach it from a laptop
through TcpProxy on port 6379.
Create Redis
Section titled “Create Redis”Pass a Project. Alchemy generates a unique name and password unless
you pass them. Default image is redis:7.
const site = yield* Railway.Project("Site");const cache = yield* Railway.Redis("Cache", { project: site });A stable name
Section titled “A stable name”Pass name when you want a stable service name. Changing it later
updates the service in place.
const cache = yield* Railway.Redis("Cache", { project: site, name: "cache",});Official Redis (redis:7) is started with --requirepass. Bitnami
reads REDIS_PASSWORD. Updating the image is in place.
const cache = yield* Railway.Redis("Cache", { project: site, image: "bitnami/redis",});Bind from a Service
Section titled “Bind from a Service”Yield Railway.ReadWriteRedis (or ReadRedis / WriteRedis) in
Service init. Provide the matching *Http layer. Runtime commands
use REDIS_URL ({name}.railway.internal).
import * as HttpServerResponse from "effect/unstable/http/HttpServerResponse";
const Cache = Railway.Redis("Cache", { project: Site });
export default class Api extends Railway.Service<Api>()( "Api", { project: Site, main: import.meta.url, port: 3000 }, Effect.gen(function* () { const cache = yield* Railway.ReadWriteRedis(Cache); return { fetch: Effect.gen(function* () { yield* cache.set("marker", "hello"); const value = yield* cache.get("marker"); return HttpServerResponse.json({ value }); }), }; }).pipe(Effect.provide(Railway.ReadWriteRedisHttp)),) {}Public TCP
Section titled “Public TCP”Attach a TcpProxy on 6379 to
reach Redis from outside the private network.
const cache = yield* Railway.Redis("Cache", { project: site });const proxy = yield* Railway.TcpProxy("CacheProxy", { redis: cache, environment: site, applicationPort: 6379,});Password
Section titled “Password”Wrap password with Redacted.make(...). If omitted, a password is
generated on first create and kept. Never persisted in attributes.
import * as Redacted from "effect/Redacted";
const cache = yield* Railway.Redis("Cache", { project: site, password: Redacted.make("…"),});Where next
Section titled “Where next”Regions lists codes.
Services is the container that binds
ReadWriteRedis.
The Redis reference lists every prop.