MCPcopy Create free account
hub / github.com/effect-app/libs / makeRedisClient

Function makeRedisClient

packages/infra/src/redis-client.ts:15–95  ·  view source on GitHub ↗
(makeClient: () => Client)

Source from the content-addressed store, hash-verified

13}
14
15export const makeRedisClient = (makeClient: () => Client) =>
16 Effect.acquireRelease(
17 Effect
18 .sync(() => {
19 const client = createClient(makeClient)
20 const lock = new Redlock([client])
21
22 function get(key: string) {
23 return Effect
24 .callback<Option.Option<string>, ConnectionException>((res) => {
25 client.get(key, (err, v) =>
26 err
27 ? res(Effect.fail(new ConnectionException(err)))
28 : res(Effect.sync(() => Option.fromNullishOr(v))))
29 })
30 .pipe(Effect.uninterruptible)
31 }
32
33 function set(key: string, val: string) {
34 return Effect
35 .callback<void, ConnectionException>((res) => {
36 client.set(key, val, (err) =>
37 err
38 ? res(Effect.fail(new ConnectionException(err)))
39 : res(Effect.sync(() => void 0)))
40 })
41 .pipe(Effect.uninterruptible)
42 }
43
44 function hset(key: string, field: string, value: string) {
45 return Effect
46 .callback<void, ConnectionException>((res) => {
47 client.hset(key, field, value, (err) =>
48 err
49 ? res(Effect.fail(new ConnectionException(err)))
50 : res(Effect.sync(() => void 0)))
51 })
52 .pipe(Effect.uninterruptible)
53 }
54
55 function hget(key: string, field: string) {
56 return Effect
57 .callback<Option.Option<string>, ConnectionException>((res) => {
58 client.hget(key, field, (err, v) =>
59 err
60 ? res(Effect.fail(new ConnectionException(err)))
61 : res(Effect.sync(() => Option.fromNullishOr(v))))
62 })
63 .pipe(Effect.uninterruptible)
64 }
65 function hmgetAll(key: string) {
66 return Effect
67 .callback<Option.Option<{ [key: string]: string }>, ConnectionException>(
68 (res) => {
69 client.hgetall(key, (err, v) =>
70 err
71 ? res(Effect.fail(new ConnectionException(err)))
72 : res(Effect.sync(() => Option.fromNullishOr(v))))

Callers 1

RedisClientLayerFunction · 0.85

Calls 4

createClientFunction · 0.85
syncMethod · 0.80
pipeMethod · 0.65
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…