-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredis.client.ts
More file actions
39 lines (36 loc) · 994 Bytes
/
redis.client.ts
File metadata and controls
39 lines (36 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Redis from "ioredis";
import type { RedisOptions } from "ioredis";
/**
* @public
* Configuration for Distributed Lock.
*/
export type DistributedLockConfig = Omit<RedisOptions, "host"> & {
/** Host Address of the Redis Node (either Cloud Native or Self-Hosted). */
host: Exclude<RedisOptions["host"], undefined>;
};
/**
* @internal
* Default Configuration for the Distributed Lock.
*/
const defaultConfiguration: Partial<DistributedLockConfig> = {
enableOfflineQueue: false,
enableReadyCheck: true,
keepAlive: 1,
keyPrefix: "<distributed-lock>",
lazyConnect: true,
maxRetriesPerRequest: 0,
};
/**
* @internal
* Factory function for creating a new instance of the Redis Client for the Distributed Lock.
*
* @param configuration - Distributed Lock Configuration.
* @returns Redis Client Instance.
*/
export const createRedisClient = (
configuration: DistributedLockConfig,
): Redis =>
new Redis({
...defaultConfiguration,
...configuration,
});