@clonegod/ttd-core 3.1.6 → 3.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,12 +17,10 @@ class LoadingCache {
17
17
  }
18
18
  init() {
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
- (0, index_1.log_info)('init redis client start');
21
20
  this.local_cache = new Map();
22
21
  this.refresh_cache_timer = new Map();
23
- yield (0, index_1.sleep)(1000);
24
- this.redis_client = yield (0, redis_client_1.getCache)('LoadingCache');
25
- (0, index_1.log_info)('init redis client done');
22
+ this.redis_client = yield (0, redis_client_1.getRedisClient)('LoadingCache');
23
+ (0, index_1.log_info)('[LoadingCache] init done');
26
24
  });
27
25
  }
28
26
  get_key(chain_id, cache_type, id) {
@@ -1,3 +1,3 @@
1
1
  import type { RedisClientType } from 'redis';
2
- declare function getCache(module_name?: string): Promise<RedisClientType>;
3
- export { getCache, };
2
+ declare function getRedisClient(module_name?: string): Promise<RedisClientType>;
3
+ export { getRedisClient, };
@@ -8,66 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getCache = getCache;
16
- const moment_1 = __importDefault(require("moment"));
12
+ exports.getRedisClient = getRedisClient;
17
13
  const redis_1 = require("redis");
18
- let redisClient;
19
- let isReady;
20
- let ip = process.env.REDIS_HOST || '127.0.0.1';
21
- let port = process.env.REDIS_PORT || '6379';
22
- let url = `redis://${ip}:${port}`;
23
- const cacheOptions = {
24
- url
25
- };
26
- let current_time = () => (0, moment_1.default)().format('YYYY-MM-DD HH:mm:ss SSS');
27
- console.log('\n\n');
28
- console.log(current_time(), `-------> Init redis start`);
29
- console.log(current_time(), `Connect to redis, url=${url}`);
30
- var first_call = true;
31
- let wait_redis_ready = (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (module_name = '') {
32
- for (let i = 1; i <= 10; i++) {
33
- try {
34
- if (!redisClient) {
35
- console.log(current_time(), module_name, `[${i}] redis not ready`);
36
- yield new Promise((r) => setTimeout(r, 1000));
37
- continue;
38
- }
39
- console.log(current_time(), module_name, `[${i}] ping...`);
40
- let res = yield redisClient.ping();
41
- console.log(current_time(), module_name, `[${i}] ping, got: ${res}`);
42
- break;
43
- }
44
- catch (err) {
45
- console.error(current_time(), module_name, `[${i}] ping, got error!`, err);
46
- }
47
- }
48
- });
49
- function getCache() {
14
+ let redisClient = null;
15
+ let connectPromise = null;
16
+ function createConnection() {
17
+ const host = process.env.REDIS_HOST || '127.0.0.1';
18
+ const port = process.env.REDIS_PORT || '6379';
19
+ const url = `redis://${host}:${port}`;
20
+ console.log(`[Redis] connecting to ${url}`);
21
+ const client = (0, redis_1.createClient)({ url });
22
+ client.on('error', (err) => console.error(`[Redis] error: ${err.message}`));
23
+ client.on('reconnecting', () => console.info('[Redis] reconnecting...'));
24
+ client.on('ready', () => console.info('[Redis] ready'));
25
+ return client.connect().then(() => {
26
+ redisClient = client;
27
+ console.info(`[Redis] connected to ${url}`);
28
+ return client;
29
+ }).catch((err) => {
30
+ redisClient = null;
31
+ connectPromise = null;
32
+ console.error(`[Redis] connect failed: ${err.message}`);
33
+ throw err;
34
+ });
35
+ }
36
+ function getRedisClient() {
50
37
  return __awaiter(this, arguments, void 0, function* (module_name = '') {
51
- if (!first_call) {
52
- yield wait_redis_ready(module_name);
53
- }
54
- first_call = false;
55
- if (!isReady) {
56
- redisClient = (0, redis_1.createClient)(Object.assign({}, cacheOptions));
57
- redisClient.on('error', err => console.error(`Redis Error: ${err}`));
58
- redisClient.on('connect', () => console.info('Redis connected'));
59
- redisClient.on('reconnecting', () => console.info('Redis reconnecting'));
60
- redisClient.on('ready', () => {
61
- isReady = true;
62
- console.info('Redis ready!');
63
- });
64
- yield redisClient.connect();
65
- }
66
- return redisClient;
38
+ if (redisClient)
39
+ return redisClient;
40
+ if (connectPromise)
41
+ return connectPromise;
42
+ connectPromise = createConnection();
43
+ return connectPromise;
67
44
  });
68
45
  }
69
- getCache().then(connection => {
70
- redisClient = connection;
71
- }).catch(err => {
72
- console.error({ err }, 'Failed to connect to Redis');
73
- });
@@ -1,14 +1,328 @@
1
1
  import { RedisClientType } from "redis";
2
- export declare class RedisCommand {
2
+ export declare class RedisClient {
3
3
  redis_client: RedisClientType;
4
- constructor();
4
+ private lockPrefix;
5
+ private lockMaxRetries;
6
+ private lockRetryDelayMs;
7
+ private lockExpireSeconds;
8
+ constructor(lockPrefix?: string);
5
9
  init(): Promise<void>;
10
+ private ensureClient;
6
11
  exists(key: string): Promise<number>;
7
12
  ttl(key: string): Promise<number>;
8
13
  expire(key: string, ttl: number): Promise<boolean>;
9
- del(key: string): Promise<number>;
14
+ del(key: string, field?: string): Promise<number>;
10
15
  set_nx(key: string, value: string): Promise<boolean>;
16
+ get(key: string): Promise<string | null>;
17
+ set(key: string, value: string, expireSeconds?: number): Promise<string | null>;
18
+ hset(key: string, field: string, value: string, expireSeconds?: number): Promise<number>;
19
+ hget(key: string, field: string): Promise<string | undefined>;
20
+ hgetall(key: string): Promise<Record<string, string>>;
21
+ hmget(key: string, fields: string[]): Promise<(string | null)[]>;
22
+ hkeys(key: string): Promise<string[]>;
23
+ hdel(key: string, field: string): Promise<number>;
24
+ hlen(key: string): Promise<number>;
11
25
  hinc(key: string, field: string, ttl?: number): Promise<number[]>;
26
+ lrange(key: string, start?: number, stop?: number): Promise<string[]>;
27
+ lpush(key: string, value: string): Promise<number>;
28
+ ltrim(key: string, start: number, stop: number): Promise<string>;
29
+ ping(): Promise<string>;
30
+ type(key: string): Promise<string>;
31
+ multi(): import("@redis/client/dist/lib/client/multi-command").RedisClientMultiCommandType<{
32
+ graph: {
33
+ CONFIG_GET: typeof import("@redis/graph/dist/commands/CONFIG_GET");
34
+ configGet: typeof import("@redis/graph/dist/commands/CONFIG_GET");
35
+ CONFIG_SET: typeof import("@redis/graph/dist/commands/CONFIG_SET");
36
+ configSet: typeof import("@redis/graph/dist/commands/CONFIG_SET");
37
+ DELETE: typeof import("@redis/graph/dist/commands/DELETE");
38
+ delete: typeof import("@redis/graph/dist/commands/DELETE");
39
+ EXPLAIN: typeof import("@redis/graph/dist/commands/EXPLAIN");
40
+ explain: typeof import("@redis/graph/dist/commands/EXPLAIN");
41
+ LIST: typeof import("@redis/graph/dist/commands/LIST");
42
+ list: typeof import("@redis/graph/dist/commands/LIST");
43
+ PROFILE: typeof import("@redis/graph/dist/commands/PROFILE");
44
+ profile: typeof import("@redis/graph/dist/commands/PROFILE");
45
+ QUERY: typeof import("@redis/graph/dist/commands/QUERY");
46
+ query: typeof import("@redis/graph/dist/commands/QUERY");
47
+ RO_QUERY: typeof import("@redis/graph/dist/commands/RO_QUERY");
48
+ roQuery: typeof import("@redis/graph/dist/commands/RO_QUERY");
49
+ SLOWLOG: typeof import("@redis/graph/dist/commands/SLOWLOG");
50
+ slowLog: typeof import("@redis/graph/dist/commands/SLOWLOG");
51
+ };
52
+ json: {
53
+ ARRAPPEND: typeof import("@redis/json/dist/commands/ARRAPPEND");
54
+ arrAppend: typeof import("@redis/json/dist/commands/ARRAPPEND");
55
+ ARRINDEX: typeof import("@redis/json/dist/commands/ARRINDEX");
56
+ arrIndex: typeof import("@redis/json/dist/commands/ARRINDEX");
57
+ ARRINSERT: typeof import("@redis/json/dist/commands/ARRINSERT");
58
+ arrInsert: typeof import("@redis/json/dist/commands/ARRINSERT");
59
+ ARRLEN: typeof import("@redis/json/dist/commands/ARRLEN");
60
+ arrLen: typeof import("@redis/json/dist/commands/ARRLEN");
61
+ ARRPOP: typeof import("@redis/json/dist/commands/ARRPOP");
62
+ arrPop: typeof import("@redis/json/dist/commands/ARRPOP");
63
+ ARRTRIM: typeof import("@redis/json/dist/commands/ARRTRIM");
64
+ arrTrim: typeof import("@redis/json/dist/commands/ARRTRIM");
65
+ DEBUG_MEMORY: typeof import("@redis/json/dist/commands/DEBUG_MEMORY");
66
+ debugMemory: typeof import("@redis/json/dist/commands/DEBUG_MEMORY");
67
+ DEL: typeof import("@redis/json/dist/commands/DEL");
68
+ del: typeof import("@redis/json/dist/commands/DEL");
69
+ FORGET: typeof import("@redis/json/dist/commands/FORGET");
70
+ forget: typeof import("@redis/json/dist/commands/FORGET");
71
+ GET: typeof import("@redis/json/dist/commands/GET");
72
+ get: typeof import("@redis/json/dist/commands/GET");
73
+ MERGE: typeof import("@redis/json/dist/commands/MERGE");
74
+ merge: typeof import("@redis/json/dist/commands/MERGE");
75
+ MGET: typeof import("@redis/json/dist/commands/MGET");
76
+ mGet: typeof import("@redis/json/dist/commands/MGET");
77
+ MSET: typeof import("@redis/json/dist/commands/MSET");
78
+ mSet: typeof import("@redis/json/dist/commands/MSET");
79
+ NUMINCRBY: typeof import("@redis/json/dist/commands/NUMINCRBY");
80
+ numIncrBy: typeof import("@redis/json/dist/commands/NUMINCRBY");
81
+ NUMMULTBY: typeof import("@redis/json/dist/commands/NUMMULTBY");
82
+ numMultBy: typeof import("@redis/json/dist/commands/NUMMULTBY");
83
+ OBJKEYS: typeof import("@redis/json/dist/commands/OBJKEYS");
84
+ objKeys: typeof import("@redis/json/dist/commands/OBJKEYS");
85
+ OBJLEN: typeof import("@redis/json/dist/commands/OBJLEN");
86
+ objLen: typeof import("@redis/json/dist/commands/OBJLEN");
87
+ RESP: typeof import("@redis/json/dist/commands/RESP");
88
+ resp: typeof import("@redis/json/dist/commands/RESP");
89
+ SET: typeof import("@redis/json/dist/commands/SET");
90
+ set: typeof import("@redis/json/dist/commands/SET");
91
+ STRAPPEND: typeof import("@redis/json/dist/commands/STRAPPEND");
92
+ strAppend: typeof import("@redis/json/dist/commands/STRAPPEND");
93
+ STRLEN: typeof import("@redis/json/dist/commands/STRLEN");
94
+ strLen: typeof import("@redis/json/dist/commands/STRLEN");
95
+ TYPE: typeof import("@redis/json/dist/commands/TYPE");
96
+ type: typeof import("@redis/json/dist/commands/TYPE");
97
+ };
98
+ ft: {
99
+ _LIST: typeof import("@redis/search/dist/commands/_LIST");
100
+ _list: typeof import("@redis/search/dist/commands/_LIST");
101
+ ALTER: typeof import("@redis/search/dist/commands/ALTER");
102
+ alter: typeof import("@redis/search/dist/commands/ALTER");
103
+ AGGREGATE_WITHCURSOR: typeof import("@redis/search/dist/commands/AGGREGATE_WITHCURSOR");
104
+ aggregateWithCursor: typeof import("@redis/search/dist/commands/AGGREGATE_WITHCURSOR");
105
+ AGGREGATE: typeof import("@redis/search/dist/commands/AGGREGATE");
106
+ aggregate: typeof import("@redis/search/dist/commands/AGGREGATE");
107
+ ALIASADD: typeof import("@redis/search/dist/commands/ALIASADD");
108
+ aliasAdd: typeof import("@redis/search/dist/commands/ALIASADD");
109
+ ALIASDEL: typeof import("@redis/search/dist/commands/ALIASDEL");
110
+ aliasDel: typeof import("@redis/search/dist/commands/ALIASDEL");
111
+ ALIASUPDATE: typeof import("@redis/search/dist/commands/ALIASUPDATE");
112
+ aliasUpdate: typeof import("@redis/search/dist/commands/ALIASUPDATE");
113
+ CONFIG_GET: typeof import("@redis/search/dist/commands/CONFIG_GET");
114
+ configGet: typeof import("@redis/search/dist/commands/CONFIG_GET");
115
+ CONFIG_SET: typeof import("@redis/search/dist/commands/CONFIG_SET");
116
+ configSet: typeof import("@redis/search/dist/commands/CONFIG_SET");
117
+ CREATE: typeof import("@redis/search/dist/commands/CREATE");
118
+ create: typeof import("@redis/search/dist/commands/CREATE");
119
+ CURSOR_DEL: typeof import("@redis/search/dist/commands/CURSOR_DEL");
120
+ cursorDel: typeof import("@redis/search/dist/commands/CURSOR_DEL");
121
+ CURSOR_READ: typeof import("@redis/search/dist/commands/CURSOR_READ");
122
+ cursorRead: typeof import("@redis/search/dist/commands/CURSOR_READ");
123
+ DICTADD: typeof import("@redis/search/dist/commands/DICTADD");
124
+ dictAdd: typeof import("@redis/search/dist/commands/DICTADD");
125
+ DICTDEL: typeof import("@redis/search/dist/commands/DICTDEL");
126
+ dictDel: typeof import("@redis/search/dist/commands/DICTDEL");
127
+ DICTDUMP: typeof import("@redis/search/dist/commands/DICTDUMP");
128
+ dictDump: typeof import("@redis/search/dist/commands/DICTDUMP");
129
+ DROPINDEX: typeof import("@redis/search/dist/commands/DROPINDEX");
130
+ dropIndex: typeof import("@redis/search/dist/commands/DROPINDEX");
131
+ EXPLAIN: typeof import("@redis/search/dist/commands/EXPLAIN");
132
+ explain: typeof import("@redis/search/dist/commands/EXPLAIN");
133
+ EXPLAINCLI: typeof import("@redis/search/dist/commands/EXPLAINCLI");
134
+ explainCli: typeof import("@redis/search/dist/commands/EXPLAINCLI");
135
+ INFO: typeof import("@redis/search/dist/commands/INFO");
136
+ info: typeof import("@redis/search/dist/commands/INFO");
137
+ PROFILESEARCH: typeof import("@redis/search/dist/commands/PROFILE_SEARCH");
138
+ profileSearch: typeof import("@redis/search/dist/commands/PROFILE_SEARCH");
139
+ PROFILEAGGREGATE: typeof import("@redis/search/dist/commands/PROFILE_AGGREGATE");
140
+ profileAggregate: typeof import("@redis/search/dist/commands/PROFILE_AGGREGATE");
141
+ SEARCH: typeof import("@redis/search/dist/commands/SEARCH");
142
+ search: typeof import("@redis/search/dist/commands/SEARCH");
143
+ SEARCH_NOCONTENT: typeof import("@redis/search/dist/commands/SEARCH_NOCONTENT");
144
+ searchNoContent: typeof import("@redis/search/dist/commands/SEARCH_NOCONTENT");
145
+ SPELLCHECK: typeof import("@redis/search/dist/commands/SPELLCHECK");
146
+ spellCheck: typeof import("@redis/search/dist/commands/SPELLCHECK");
147
+ SUGADD: typeof import("@redis/search/dist/commands/SUGADD");
148
+ sugAdd: typeof import("@redis/search/dist/commands/SUGADD");
149
+ SUGDEL: typeof import("@redis/search/dist/commands/SUGDEL");
150
+ sugDel: typeof import("@redis/search/dist/commands/SUGDEL");
151
+ SUGGET_WITHPAYLOADS: typeof import("@redis/search/dist/commands/SUGGET_WITHPAYLOADS");
152
+ sugGetWithPayloads: typeof import("@redis/search/dist/commands/SUGGET_WITHPAYLOADS");
153
+ SUGGET_WITHSCORES_WITHPAYLOADS: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS");
154
+ sugGetWithScoresWithPayloads: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES_WITHPAYLOADS");
155
+ SUGGET_WITHSCORES: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES");
156
+ sugGetWithScores: typeof import("@redis/search/dist/commands/SUGGET_WITHSCORES");
157
+ SUGGET: typeof import("@redis/search/dist/commands/SUGGET");
158
+ sugGet: typeof import("@redis/search/dist/commands/SUGGET");
159
+ SUGLEN: typeof import("@redis/search/dist/commands/SUGLEN");
160
+ sugLen: typeof import("@redis/search/dist/commands/SUGLEN");
161
+ SYNDUMP: typeof import("@redis/search/dist/commands/SYNDUMP");
162
+ synDump: typeof import("@redis/search/dist/commands/SYNDUMP");
163
+ SYNUPDATE: typeof import("@redis/search/dist/commands/SYNUPDATE");
164
+ synUpdate: typeof import("@redis/search/dist/commands/SYNUPDATE");
165
+ TAGVALS: typeof import("@redis/search/dist/commands/TAGVALS");
166
+ tagVals: typeof import("@redis/search/dist/commands/TAGVALS");
167
+ };
168
+ ts: {
169
+ ADD: typeof import("@redis/time-series/dist/commands/ADD");
170
+ add: typeof import("@redis/time-series/dist/commands/ADD");
171
+ ALTER: typeof import("@redis/time-series/dist/commands/ALTER");
172
+ alter: typeof import("@redis/time-series/dist/commands/ALTER");
173
+ CREATE: typeof import("@redis/time-series/dist/commands/CREATE");
174
+ create: typeof import("@redis/time-series/dist/commands/CREATE");
175
+ CREATERULE: typeof import("@redis/time-series/dist/commands/CREATERULE");
176
+ createRule: typeof import("@redis/time-series/dist/commands/CREATERULE");
177
+ DECRBY: typeof import("@redis/time-series/dist/commands/DECRBY");
178
+ decrBy: typeof import("@redis/time-series/dist/commands/DECRBY");
179
+ DEL: typeof import("@redis/time-series/dist/commands/DEL");
180
+ del: typeof import("@redis/time-series/dist/commands/DEL");
181
+ DELETERULE: typeof import("@redis/time-series/dist/commands/DELETERULE");
182
+ deleteRule: typeof import("@redis/time-series/dist/commands/DELETERULE");
183
+ GET: typeof import("@redis/time-series/dist/commands/GET");
184
+ get: typeof import("@redis/time-series/dist/commands/GET");
185
+ INCRBY: typeof import("@redis/time-series/dist/commands/INCRBY");
186
+ incrBy: typeof import("@redis/time-series/dist/commands/INCRBY");
187
+ INFO_DEBUG: typeof import("@redis/time-series/dist/commands/INFO_DEBUG");
188
+ infoDebug: typeof import("@redis/time-series/dist/commands/INFO_DEBUG");
189
+ INFO: typeof import("@redis/time-series/dist/commands/INFO");
190
+ info: typeof import("@redis/time-series/dist/commands/INFO");
191
+ MADD: typeof import("@redis/time-series/dist/commands/MADD");
192
+ mAdd: typeof import("@redis/time-series/dist/commands/MADD");
193
+ MGET: typeof import("@redis/time-series/dist/commands/MGET");
194
+ mGet: typeof import("@redis/time-series/dist/commands/MGET");
195
+ MGET_WITHLABELS: typeof import("@redis/time-series/dist/commands/MGET_WITHLABELS");
196
+ mGetWithLabels: typeof import("@redis/time-series/dist/commands/MGET_WITHLABELS");
197
+ QUERYINDEX: typeof import("@redis/time-series/dist/commands/QUERYINDEX");
198
+ queryIndex: typeof import("@redis/time-series/dist/commands/QUERYINDEX");
199
+ RANGE: typeof import("@redis/time-series/dist/commands/RANGE");
200
+ range: typeof import("@redis/time-series/dist/commands/RANGE");
201
+ REVRANGE: typeof import("@redis/time-series/dist/commands/REVRANGE");
202
+ revRange: typeof import("@redis/time-series/dist/commands/REVRANGE");
203
+ MRANGE: typeof import("@redis/time-series/dist/commands/MRANGE");
204
+ mRange: typeof import("@redis/time-series/dist/commands/MRANGE");
205
+ MRANGE_WITHLABELS: typeof import("@redis/time-series/dist/commands/MRANGE_WITHLABELS");
206
+ mRangeWithLabels: typeof import("@redis/time-series/dist/commands/MRANGE_WITHLABELS");
207
+ MREVRANGE: typeof import("@redis/time-series/dist/commands/MREVRANGE");
208
+ mRevRange: typeof import("@redis/time-series/dist/commands/MREVRANGE");
209
+ MREVRANGE_WITHLABELS: typeof import("@redis/time-series/dist/commands/MREVRANGE_WITHLABELS");
210
+ mRevRangeWithLabels: typeof import("@redis/time-series/dist/commands/MREVRANGE_WITHLABELS");
211
+ };
212
+ bf: {
213
+ ADD: typeof import("@redis/bloom/dist/commands/bloom/ADD");
214
+ add: typeof import("@redis/bloom/dist/commands/bloom/ADD");
215
+ CARD: typeof import("@redis/bloom/dist/commands/bloom/CARD");
216
+ card: typeof import("@redis/bloom/dist/commands/bloom/CARD");
217
+ EXISTS: typeof import("@redis/bloom/dist/commands/bloom/EXISTS");
218
+ exists: typeof import("@redis/bloom/dist/commands/bloom/EXISTS");
219
+ INFO: typeof import("@redis/bloom/dist/commands/bloom/INFO");
220
+ info: typeof import("@redis/bloom/dist/commands/bloom/INFO");
221
+ INSERT: typeof import("@redis/bloom/dist/commands/bloom/INSERT");
222
+ insert: typeof import("@redis/bloom/dist/commands/bloom/INSERT");
223
+ LOADCHUNK: typeof import("@redis/bloom/dist/commands/bloom/LOADCHUNK");
224
+ loadChunk: typeof import("@redis/bloom/dist/commands/bloom/LOADCHUNK");
225
+ MADD: typeof import("@redis/bloom/dist/commands/bloom/MADD");
226
+ mAdd: typeof import("@redis/bloom/dist/commands/bloom/MADD");
227
+ MEXISTS: typeof import("@redis/bloom/dist/commands/bloom/MEXISTS");
228
+ mExists: typeof import("@redis/bloom/dist/commands/bloom/MEXISTS");
229
+ RESERVE: typeof import("@redis/bloom/dist/commands/bloom/RESERVE");
230
+ reserve: typeof import("@redis/bloom/dist/commands/bloom/RESERVE");
231
+ SCANDUMP: typeof import("@redis/bloom/dist/commands/bloom/SCANDUMP");
232
+ scanDump: typeof import("@redis/bloom/dist/commands/bloom/SCANDUMP");
233
+ };
234
+ cms: {
235
+ INCRBY: typeof import("@redis/bloom/dist/commands/count-min-sketch/INCRBY");
236
+ incrBy: typeof import("@redis/bloom/dist/commands/count-min-sketch/INCRBY");
237
+ INFO: typeof import("@redis/bloom/dist/commands/count-min-sketch/INFO");
238
+ info: typeof import("@redis/bloom/dist/commands/count-min-sketch/INFO");
239
+ INITBYDIM: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYDIM");
240
+ initByDim: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYDIM");
241
+ INITBYPROB: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYPROB");
242
+ initByProb: typeof import("@redis/bloom/dist/commands/count-min-sketch/INITBYPROB");
243
+ MERGE: typeof import("@redis/bloom/dist/commands/count-min-sketch/MERGE");
244
+ merge: typeof import("@redis/bloom/dist/commands/count-min-sketch/MERGE");
245
+ QUERY: typeof import("@redis/bloom/dist/commands/count-min-sketch/QUERY");
246
+ query: typeof import("@redis/bloom/dist/commands/count-min-sketch/QUERY");
247
+ };
248
+ cf: {
249
+ ADD: typeof import("@redis/bloom/dist/commands/cuckoo/ADD");
250
+ add: typeof import("@redis/bloom/dist/commands/cuckoo/ADD");
251
+ ADDNX: typeof import("@redis/bloom/dist/commands/cuckoo/ADDNX");
252
+ addNX: typeof import("@redis/bloom/dist/commands/cuckoo/ADDNX");
253
+ COUNT: typeof import("@redis/bloom/dist/commands/cuckoo/COUNT");
254
+ count: typeof import("@redis/bloom/dist/commands/cuckoo/COUNT");
255
+ DEL: typeof import("@redis/bloom/dist/commands/cuckoo/DEL");
256
+ del: typeof import("@redis/bloom/dist/commands/cuckoo/DEL");
257
+ EXISTS: typeof import("@redis/bloom/dist/commands/cuckoo/EXISTS");
258
+ exists: typeof import("@redis/bloom/dist/commands/cuckoo/EXISTS");
259
+ INFO: typeof import("@redis/bloom/dist/commands/cuckoo/INFO");
260
+ info: typeof import("@redis/bloom/dist/commands/cuckoo/INFO");
261
+ INSERT: typeof import("@redis/bloom/dist/commands/cuckoo/INSERT");
262
+ insert: typeof import("@redis/bloom/dist/commands/cuckoo/INSERT");
263
+ INSERTNX: typeof import("@redis/bloom/dist/commands/cuckoo/INSERTNX");
264
+ insertNX: typeof import("@redis/bloom/dist/commands/cuckoo/INSERTNX");
265
+ LOADCHUNK: typeof import("@redis/bloom/dist/commands/cuckoo/LOADCHUNK");
266
+ loadChunk: typeof import("@redis/bloom/dist/commands/cuckoo/LOADCHUNK");
267
+ RESERVE: typeof import("@redis/bloom/dist/commands/cuckoo/RESERVE");
268
+ reserve: typeof import("@redis/bloom/dist/commands/cuckoo/RESERVE");
269
+ SCANDUMP: typeof import("@redis/bloom/dist/commands/cuckoo/SCANDUMP");
270
+ scanDump: typeof import("@redis/bloom/dist/commands/cuckoo/SCANDUMP");
271
+ };
272
+ tDigest: {
273
+ ADD: typeof import("@redis/bloom/dist/commands/t-digest/ADD");
274
+ add: typeof import("@redis/bloom/dist/commands/t-digest/ADD");
275
+ BYRANK: typeof import("@redis/bloom/dist/commands/t-digest/BYRANK");
276
+ byRank: typeof import("@redis/bloom/dist/commands/t-digest/BYRANK");
277
+ BYREVRANK: typeof import("@redis/bloom/dist/commands/t-digest/BYREVRANK");
278
+ byRevRank: typeof import("@redis/bloom/dist/commands/t-digest/BYREVRANK");
279
+ CDF: typeof import("@redis/bloom/dist/commands/t-digest/CDF");
280
+ cdf: typeof import("@redis/bloom/dist/commands/t-digest/CDF");
281
+ CREATE: typeof import("@redis/bloom/dist/commands/t-digest/CREATE");
282
+ create: typeof import("@redis/bloom/dist/commands/t-digest/CREATE");
283
+ INFO: typeof import("@redis/bloom/dist/commands/t-digest/INFO");
284
+ info: typeof import("@redis/bloom/dist/commands/t-digest/INFO");
285
+ MAX: typeof import("@redis/bloom/dist/commands/t-digest/MAX");
286
+ max: typeof import("@redis/bloom/dist/commands/t-digest/MAX");
287
+ MERGE: typeof import("@redis/bloom/dist/commands/t-digest/MERGE");
288
+ merge: typeof import("@redis/bloom/dist/commands/t-digest/MERGE");
289
+ MIN: typeof import("@redis/bloom/dist/commands/t-digest/MIN");
290
+ min: typeof import("@redis/bloom/dist/commands/t-digest/MIN");
291
+ QUANTILE: typeof import("@redis/bloom/dist/commands/t-digest/QUANTILE");
292
+ quantile: typeof import("@redis/bloom/dist/commands/t-digest/QUANTILE");
293
+ RANK: typeof import("@redis/bloom/dist/commands/t-digest/RANK");
294
+ rank: typeof import("@redis/bloom/dist/commands/t-digest/RANK");
295
+ RESET: typeof import("@redis/bloom/dist/commands/t-digest/RESET");
296
+ reset: typeof import("@redis/bloom/dist/commands/t-digest/RESET");
297
+ REVRANK: typeof import("@redis/bloom/dist/commands/t-digest/REVRANK");
298
+ revRank: typeof import("@redis/bloom/dist/commands/t-digest/REVRANK");
299
+ TRIMMED_MEAN: typeof import("@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN");
300
+ trimmedMean: typeof import("@redis/bloom/dist/commands/t-digest/TRIMMED_MEAN");
301
+ };
302
+ topK: {
303
+ ADD: typeof import("@redis/bloom/dist/commands/top-k/ADD");
304
+ add: typeof import("@redis/bloom/dist/commands/top-k/ADD");
305
+ COUNT: typeof import("@redis/bloom/dist/commands/top-k/COUNT");
306
+ count: typeof import("@redis/bloom/dist/commands/top-k/COUNT");
307
+ INCRBY: typeof import("@redis/bloom/dist/commands/top-k/INCRBY");
308
+ incrBy: typeof import("@redis/bloom/dist/commands/top-k/INCRBY");
309
+ INFO: typeof import("@redis/bloom/dist/commands/top-k/INFO");
310
+ info: typeof import("@redis/bloom/dist/commands/top-k/INFO");
311
+ LIST_WITHCOUNT: typeof import("@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT");
312
+ listWithCount: typeof import("@redis/bloom/dist/commands/top-k/LIST_WITHCOUNT");
313
+ LIST: typeof import("@redis/bloom/dist/commands/top-k/LIST");
314
+ list: typeof import("@redis/bloom/dist/commands/top-k/LIST");
315
+ QUERY: typeof import("@redis/bloom/dist/commands/top-k/QUERY");
316
+ query: typeof import("@redis/bloom/dist/commands/top-k/QUERY");
317
+ RESERVE: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
318
+ reserve: typeof import("@redis/bloom/dist/commands/top-k/RESERVE");
319
+ };
320
+ }, Record<string, never>, Record<string, never>>;
321
+ private getLockKey;
322
+ acquireLock(lock_key: string, lock_value: string, expireSeconds?: number): Promise<boolean>;
323
+ releaseLock(lock_key: string, lock_value: string): Promise<boolean>;
324
+ withLock<T>(lock_identifier: string, callback: () => Promise<T>, release_lock_delay_ms?: number): Promise<T>;
12
325
  subscribe(channel: string, listener: any): Promise<void>;
13
326
  publish(channel: string, message: string): Promise<void>;
14
327
  }
328
+ export declare const RedisCommand: typeof RedisClient;
@@ -9,18 +9,29 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  });
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.RedisCommand = void 0;
12
+ exports.RedisCommand = exports.RedisClient = void 0;
13
13
  const index_1 = require("../index");
14
14
  const redis_client_1 = require("./redis_client");
15
- class RedisCommand {
16
- constructor() {
15
+ const MAX_SUBSCRIBE_RECONNECT = 10;
16
+ class RedisClient {
17
+ constructor(lockPrefix = '') {
18
+ this.lockMaxRetries = 10;
19
+ this.lockRetryDelayMs = 300;
20
+ this.lockExpireSeconds = 3;
21
+ this.lockPrefix = lockPrefix;
17
22
  }
18
23
  init() {
19
24
  return __awaiter(this, void 0, void 0, function* () {
20
- (0, index_1.log_info)('init redis client start');
21
- yield (0, index_1.sleep)(1000);
22
- this.redis_client = yield (0, redis_client_1.getCache)('RedisCommand');
23
- (0, index_1.log_info)('init redis client done');
25
+ this.redis_client = yield (0, redis_client_1.getRedisClient)('RedisClient');
26
+ (0, index_1.log_info)('[RedisClient] init done');
27
+ });
28
+ }
29
+ ensureClient() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ if (!this.redis_client) {
32
+ this.redis_client = yield (0, redis_client_1.getRedisClient)('RedisClient');
33
+ }
34
+ return this.redis_client;
24
35
  });
25
36
  }
26
37
  exists(key) {
@@ -38,8 +49,11 @@ class RedisCommand {
38
49
  return yield this.redis_client.expire(key, ttl);
39
50
  });
40
51
  }
41
- del(key) {
42
- return __awaiter(this, void 0, void 0, function* () {
52
+ del(key_1) {
53
+ return __awaiter(this, arguments, void 0, function* (key, field = '') {
54
+ if (field) {
55
+ return yield this.redis_client.hDel(key, field);
56
+ }
43
57
  return yield this.redis_client.del(key);
44
58
  });
45
59
  }
@@ -48,6 +62,71 @@ class RedisCommand {
48
62
  return yield this.redis_client.setNX(key, value);
49
63
  });
50
64
  }
65
+ get(key) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ const client = yield this.ensureClient();
68
+ return yield client.get(key);
69
+ });
70
+ }
71
+ set(key, value, expireSeconds) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const client = yield this.ensureClient();
74
+ if (expireSeconds && expireSeconds > 0) {
75
+ return yield client.set(key, value, { EX: expireSeconds });
76
+ }
77
+ return yield client.set(key, value);
78
+ });
79
+ }
80
+ hset(key, field, value, expireSeconds) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ const client = yield this.ensureClient();
83
+ const res = yield client.hSet(key, field, value);
84
+ if (expireSeconds && expireSeconds > 0) {
85
+ try {
86
+ yield client.hExpire(key, field, expireSeconds);
87
+ }
88
+ catch (_) {
89
+ }
90
+ }
91
+ return res;
92
+ });
93
+ }
94
+ hget(key, field) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ const client = yield this.ensureClient();
97
+ return yield client.hGet(key, field);
98
+ });
99
+ }
100
+ hgetall(key) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ const client = yield this.ensureClient();
103
+ return yield client.hGetAll(key);
104
+ });
105
+ }
106
+ hmget(key, fields) {
107
+ return __awaiter(this, void 0, void 0, function* () {
108
+ const client = yield this.ensureClient();
109
+ return yield client.hmGet(key, fields);
110
+ });
111
+ }
112
+ hkeys(key) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const client = yield this.ensureClient();
115
+ return yield client.hKeys(key);
116
+ });
117
+ }
118
+ hdel(key, field) {
119
+ return __awaiter(this, void 0, void 0, function* () {
120
+ const client = yield this.ensureClient();
121
+ return yield client.hDel(key, field);
122
+ });
123
+ }
124
+ hlen(key) {
125
+ return __awaiter(this, void 0, void 0, function* () {
126
+ const client = yield this.ensureClient();
127
+ return yield client.hLen(key);
128
+ });
129
+ }
51
130
  hinc(key_1, field_1) {
52
131
  return __awaiter(this, arguments, void 0, function* (key, field, ttl = 3600) {
53
132
  let res = [];
@@ -60,18 +139,140 @@ class RedisCommand {
60
139
  return res;
61
140
  });
62
141
  }
142
+ lrange(key_1) {
143
+ return __awaiter(this, arguments, void 0, function* (key, start = 0, stop = -1) {
144
+ const client = yield this.ensureClient();
145
+ return yield client.lRange(key, start, stop);
146
+ });
147
+ }
148
+ lpush(key, value) {
149
+ return __awaiter(this, void 0, void 0, function* () {
150
+ const client = yield this.ensureClient();
151
+ return yield client.lPush(key, value);
152
+ });
153
+ }
154
+ ltrim(key, start, stop) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ const client = yield this.ensureClient();
157
+ return yield client.lTrim(key, start, stop);
158
+ });
159
+ }
160
+ ping() {
161
+ return __awaiter(this, void 0, void 0, function* () {
162
+ const client = yield this.ensureClient();
163
+ return yield client.ping();
164
+ });
165
+ }
166
+ type(key) {
167
+ return __awaiter(this, void 0, void 0, function* () {
168
+ const client = yield this.ensureClient();
169
+ return yield client.type(key);
170
+ });
171
+ }
172
+ multi() {
173
+ return this.redis_client.multi();
174
+ }
175
+ getLockKey(lock_identifier) {
176
+ return `${this.lockPrefix}:lock:${lock_identifier}`;
177
+ }
178
+ acquireLock(lock_key_1, lock_value_1) {
179
+ return __awaiter(this, arguments, void 0, function* (lock_key, lock_value, expireSeconds = this.lockExpireSeconds) {
180
+ const client = yield this.ensureClient();
181
+ const result = yield client.set(lock_key, lock_value, {
182
+ NX: true,
183
+ EX: expireSeconds,
184
+ });
185
+ (0, index_1.log_info)(`[Lock] try acquire: key=${lock_key}, value=${lock_value}, expire=${expireSeconds}s, result=${result}`);
186
+ return result === 'OK';
187
+ });
188
+ }
189
+ releaseLock(lock_key, lock_value) {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ const client = yield this.ensureClient();
192
+ const script = `
193
+ if redis.call('get', KEYS[1]) == ARGV[1] then
194
+ return redis.call('del', KEYS[1])
195
+ else
196
+ return 0
197
+ end
198
+ `;
199
+ const result = yield client.eval(script, {
200
+ keys: [lock_key],
201
+ arguments: [lock_value],
202
+ });
203
+ return Number(result) === 1;
204
+ });
205
+ }
206
+ withLock(lock_identifier_1, callback_1) {
207
+ return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 100) {
208
+ const lock_key = this.getLockKey(lock_identifier);
209
+ const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
210
+ let retries = 0;
211
+ let acquired = false;
212
+ const firstTryTime = Date.now();
213
+ let getLockTime = 0;
214
+ try {
215
+ while (retries < this.lockMaxRetries) {
216
+ acquired = yield this.acquireLock(lock_key, lock_value);
217
+ if (acquired)
218
+ break;
219
+ yield new Promise(resolve => setTimeout(resolve, this.lockRetryDelayMs));
220
+ retries++;
221
+ }
222
+ if (acquired) {
223
+ getLockTime = Date.now();
224
+ return yield callback();
225
+ }
226
+ }
227
+ finally {
228
+ if (acquired) {
229
+ const releaseDelay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
230
+ if (releaseDelay > 0) {
231
+ yield (0, index_1.sleep)(releaseDelay);
232
+ }
233
+ this.releaseLock(lock_key, lock_value);
234
+ (0, index_1.log_info)(`[Lock] withLock ok: key=${lock_key}, retries=${retries}, wait=${getLockTime - firstTryTime}ms, hold=${Date.now() - getLockTime}ms`);
235
+ }
236
+ else {
237
+ (0, index_1.log_warn)(`[Lock] withLock failed: key=${lock_key}, retries=${retries}, took=${Date.now() - firstTryTime}ms`);
238
+ throw new Error(`get lock for ${lock_key} failed`);
239
+ }
240
+ }
241
+ });
242
+ }
63
243
  subscribe(channel, listener) {
64
244
  return __awaiter(this, void 0, void 0, function* () {
65
- let subscriber = this.redis_client.duplicate();
66
- subscriber.on('error', (err) => __awaiter(this, void 0, void 0, function* () {
67
- let mills = 3000;
68
- (0, index_1.log_error)(`subscribe channel error! channel: ${channel}`, err);
69
- (0, index_1.log_info)(`wait ${mills} ms, re-subscribe channel: ${channel}`);
70
- yield (0, index_1.sleep)(mills);
71
- this.subscribe(channel, listener);
72
- }));
73
- yield subscriber.connect();
74
- subscriber.subscribe(channel, listener);
245
+ let reconnectCount = 0;
246
+ const doSubscribe = () => __awaiter(this, void 0, void 0, function* () {
247
+ try {
248
+ const subscriber = this.redis_client.duplicate();
249
+ subscriber.on('error', (err) => __awaiter(this, void 0, void 0, function* () {
250
+ (0, index_1.log_error)(`[PubSub] channel=${channel} error`, err);
251
+ if (reconnectCount >= MAX_SUBSCRIBE_RECONNECT) {
252
+ (0, index_1.log_warn)(`[PubSub] channel=${channel} exceeded max reconnect (${MAX_SUBSCRIBE_RECONNECT}), giving up`);
253
+ return;
254
+ }
255
+ reconnectCount++;
256
+ const delay = Math.min(1000 * reconnectCount, 10000);
257
+ (0, index_1.log_info)(`[PubSub] channel=${channel} reconnect #${reconnectCount} in ${delay}ms`);
258
+ yield (0, index_1.sleep)(delay);
259
+ doSubscribe();
260
+ }));
261
+ yield subscriber.connect();
262
+ yield subscriber.subscribe(channel, listener);
263
+ reconnectCount = 0;
264
+ (0, index_1.log_info)(`[PubSub] subscribed to ${channel}`);
265
+ }
266
+ catch (err) {
267
+ (0, index_1.log_error)(`[PubSub] subscribe to ${channel} failed`, err);
268
+ if (reconnectCount < MAX_SUBSCRIBE_RECONNECT) {
269
+ reconnectCount++;
270
+ yield (0, index_1.sleep)(3000);
271
+ doSubscribe();
272
+ }
273
+ }
274
+ });
275
+ yield doSubscribe();
75
276
  });
76
277
  }
77
278
  publish(channel, message) {
@@ -80,4 +281,5 @@ class RedisCommand {
80
281
  });
81
282
  }
82
283
  }
83
- exports.RedisCommand = RedisCommand;
284
+ exports.RedisClient = RedisClient;
285
+ exports.RedisCommand = RedisClient;
package/dist/index.d.ts CHANGED
@@ -133,9 +133,11 @@ export declare const format_unique_orderbook_id: (chain_id: CHAIN_ID, dex_id: DE
133
133
  export declare const parse_unique_orderbook_id: (unique_orderbook_id: string) => UniqueOrderbookIdType;
134
134
  export declare const format_unique_order_msg_id: (group_id: string, price_id: string, order_trace_id: string) => string;
135
135
  export declare const format_order_lock_key: (chain_id: string, group_id: string, price_id: string, order_trace_id: string) => string;
136
+ export declare const getRedisClient: () => Promise<import("redis").RedisClientType>;
136
137
  export declare const getRedisCache: () => Promise<import("redis").RedisClientType>;
137
138
  export declare const getLoadingCache: () => cache.LoadingCache;
138
- export declare const getRedisCommamd: () => cache.RedisCommand;
139
+ export declare const getRedisCommamd: () => cache.RedisClient;
140
+ export declare const createRedisClient: (lockPrefix?: string) => cache.RedisClient;
139
141
  export declare const getArbCache: (env_args: any) => cache.ArbCache;
140
142
  export declare const getArbEventPublisher: (arb_cache: any) => cache.ArbEventPublisher;
141
143
  export declare const getArbEventSubscriber: (arb_cache: any) => cache.ArbEventSubscriber;
package/dist/index.js CHANGED
@@ -48,8 +48,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.DATE_TIME_FORMAT_DEFAULT = exports.to_json_str = exports.DecimalUtil = exports.generateRandomNumber = exports.LOG = exports._active_log_level = exports.LOG_LEVEL = exports.REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE = exports.REDIS_EVENT_TYPE_ORDER = exports.REDIS_EVENT_TYPE_QUOTE = exports.REDIS_EVENT_TYPE_CONFIG_CHANGE = exports.REDIS_EVENT_CHANNEL = exports.get_new_block_channel_name = exports.get_tx_result_channel_name = exports.get_wallet_raw_tx_channel_name = exports.get_order_channel_name = exports.get_quote_channel_name = exports.get_config_channel_name = exports.get_cache_key = exports.getArbEventSubscriber = exports.getArbEventPublisher = exports.getArbCache = exports.getRedisCommamd = exports.getLoadingCache = exports.getRedisCache = exports.format_order_lock_key = exports.format_unique_order_msg_id = exports.parse_unique_orderbook_id = exports.format_unique_orderbook_id = exports.format_symbol_name = exports.LOCAL_EVENT_NAME = exports.CACHE_KEY_TYPE = exports.OnChainDataSubscribeType = exports.TradeErrorCodeType = exports.SystemErrorCodeType = exports.TRADE_TYPE = exports.GROUP_ID = exports.DEX_ID = exports.CHAIN_ID = exports.STREAMING_TRANSACTION_CONFIRMED = exports.TRANSACTION_STATE_FAILED = exports.TRANSACTION_STATE_SUCCESS = exports.TRANSACTION_STATE_PROCESSING = exports.QUOTE_AMOUNT_USD_MAX = exports.QUOTE_AMOUNT_USD_MIN = exports.REGEX_HEX_PREFIX = exports.PROCESSING = exports.NOT_FOUND = exports.SUCCESS = exports.FAILED = void 0;
52
- exports.execute_bash = exports.inspect_arb_local_cache = exports.save_trade_execution_logs = exports.parse_trade_cmdline_args = exports.get_input_out_token_fix = exports.get_input_out_token = exports.calc_amount_in_token = exports.estimate_amount_in_token = exports.failed = exports.success = exports.home_dir = exports.postJSON = exports.deep_merge_object = exports.isArray = exports.isTrue = exports.deep_clone = exports.uuid = exports.DATE_TIME_FORMAT_NO_WHITESPACE = void 0;
51
+ exports.DecimalUtil = exports.generateRandomNumber = exports.LOG = exports._active_log_level = exports.LOG_LEVEL = exports.REDIS_EVENT_TYPE_TRADE_INSTANCE_CHANGE = exports.REDIS_EVENT_TYPE_ORDER = exports.REDIS_EVENT_TYPE_QUOTE = exports.REDIS_EVENT_TYPE_CONFIG_CHANGE = exports.REDIS_EVENT_CHANNEL = exports.get_new_block_channel_name = exports.get_tx_result_channel_name = exports.get_wallet_raw_tx_channel_name = exports.get_order_channel_name = exports.get_quote_channel_name = exports.get_config_channel_name = exports.get_cache_key = exports.getArbEventSubscriber = exports.getArbEventPublisher = exports.getArbCache = exports.createRedisClient = exports.getRedisCommamd = exports.getLoadingCache = exports.getRedisCache = exports.getRedisClient = exports.format_order_lock_key = exports.format_unique_order_msg_id = exports.parse_unique_orderbook_id = exports.format_unique_orderbook_id = exports.format_symbol_name = exports.LOCAL_EVENT_NAME = exports.CACHE_KEY_TYPE = exports.OnChainDataSubscribeType = exports.TradeErrorCodeType = exports.SystemErrorCodeType = exports.TRADE_TYPE = exports.GROUP_ID = exports.DEX_ID = exports.CHAIN_ID = exports.STREAMING_TRANSACTION_CONFIRMED = exports.TRANSACTION_STATE_FAILED = exports.TRANSACTION_STATE_SUCCESS = exports.TRANSACTION_STATE_PROCESSING = exports.QUOTE_AMOUNT_USD_MAX = exports.QUOTE_AMOUNT_USD_MIN = exports.REGEX_HEX_PREFIX = exports.PROCESSING = exports.NOT_FOUND = exports.SUCCESS = exports.FAILED = void 0;
52
+ exports.execute_bash = exports.inspect_arb_local_cache = exports.save_trade_execution_logs = exports.parse_trade_cmdline_args = exports.get_input_out_token_fix = exports.get_input_out_token = exports.calc_amount_in_token = exports.estimate_amount_in_token = exports.failed = exports.success = exports.home_dir = exports.postJSON = exports.deep_merge_object = exports.isArray = exports.isTrue = exports.deep_clone = exports.uuid = exports.DATE_TIME_FORMAT_NO_WHITESPACE = exports.DATE_TIME_FORMAT_DEFAULT = exports.to_json_str = void 0;
53
53
  exports._caller = _caller;
54
54
  exports.log_trace = log_trace;
55
55
  exports.log_debug = log_debug;
@@ -254,19 +254,23 @@ const format_order_lock_key = (chain_id, group_id, price_id, order_trace_id) =>
254
254
  return `${chain_id}:lock:${group_id}:${price_id}:${order_trace_id}`;
255
255
  };
256
256
  exports.format_order_lock_key = format_order_lock_key;
257
- const getRedisCache = () => __awaiter(void 0, void 0, void 0, function* () {
258
- yield sleep(1000);
259
- return cache.getCache();
257
+ const getRedisClient = () => __awaiter(void 0, void 0, void 0, function* () {
258
+ return cache.getRedisClient();
260
259
  });
261
- exports.getRedisCache = getRedisCache;
260
+ exports.getRedisClient = getRedisClient;
261
+ exports.getRedisCache = exports.getRedisClient;
262
262
  const getLoadingCache = () => {
263
263
  return new cache.LoadingCache();
264
264
  };
265
265
  exports.getLoadingCache = getLoadingCache;
266
266
  const getRedisCommamd = () => {
267
- return new cache.RedisCommand();
267
+ return new cache.RedisClient();
268
268
  };
269
269
  exports.getRedisCommamd = getRedisCommamd;
270
+ const createRedisClient = (lockPrefix = '') => {
271
+ return new cache.RedisClient(lockPrefix);
272
+ };
273
+ exports.createRedisClient = createRedisClient;
270
274
  const getArbCache = (env_args) => {
271
275
  return new cache.ArbCache(env_args);
272
276
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-core",
3
- "version": "3.1.6",
3
+ "version": "3.1.8",
4
4
  "description": "Common types and utilities for trading systems - use `npm run push` to publish",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",