(makeClient: () => Client)
| 13 | } |
| 14 | |
| 15 | export 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)))) |
no test coverage detected
searching dependent graphs…