@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
md 60 lines 1.81 KB
Rendered Raw
1 # @alchemy.run/redis
2
3 The Redis client behind [Alchemy](https://alchemy.run)'s Redis bindings. A dependency-free RESP client whose commands are Effects with typed errors. It connects over TCP or TLS on Node and Bun.
4
5 ```sh
6 npm install alchemy @alchemy.run/redis effect
7 ```
8
9 You usually get this client from a binding. `Fly.ReadWriteRedis` and `Railway.ReadWriteRedis` connect it to the Redis they deploy:
10
11 ```typescript
12 // src/api.ts
13 import * as Railway from "@alchemy.run/railway";
14 import * as Effect from "effect/Effect";
15 import * as HttpServerResponse from "effect/http/HttpServerResponse";
16
17 export const Site = Railway.Project("Site");
18 export const Cache = Railway.Redis("Cache", { project: Site });
19
20 export default class Api extends Railway.Service<Api>()(
21 "Api",
22 { project: Site, main: import.meta.url, port: 3000 },
23 Effect.gen(function* () {
24 const cache = yield* Railway.ReadWriteRedis(Cache);
25
26 return {
27 fetch: Effect.gen(function* () {
28 const visits = yield* cache.incr("visits");
29 return yield* HttpServerResponse.json({ visits });
30 }).pipe(Effect.orDie),
31 };
32 }).pipe(Effect.provide(Railway.ReadWriteRedisHttp)),
33 ) {}
34 ```
35
36 Point it at any other Redis by URL:
37
38 ```typescript
39 // src/cache.ts
40 import * as Redis from "@alchemy.run/redis";
41 import * as Config from "effect/Config";
42 import * as Effect from "effect/Effect";
43
44 const url = Config.String("REDIS_URL").pipe(
45 Effect.mapError(() => new Redis.UrlMissing({ name: "cache" })),
46 );
47
48 export const cache = Redis.makeReadWrite(url);
49
50 export const program = Effect.gen(function* () {
51 yield* cache.set("greeting", "hello", { ex: 60 });
52 return yield* cache.get("greeting");
53 });
54 ```
55
56 ## Learn more
57
58 - [Redis on Fly.io](https://alchemy.run/fly/data/redis)
59 - [Redis on Railway](https://alchemy.run/railway/data/redis)
60 - [Alchemy](https://alchemy.run)