redis-abstraction 1.0.11 → 2.0.12

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.
@@ -44,4 +44,8 @@ export interface IRedisClientPool {
44
44
  * @param prefix An identity string for token to prepend.
45
45
  */
46
46
  generateUniqueToken(prefix: string): string;
47
+ /**
48
+ * This method should initialize the pool and all the required resources before acquiring any client. Call this method before calling any method.
49
+ */
50
+ initialize(): Promise<void>;
47
51
  }
@@ -16,6 +16,7 @@ export declare class IORedisClientPool<redisConnectionType extends TIORedisCommo
16
16
  private idlePoolSize;
17
17
  private totalConnectionCounter;
18
18
  constructor(redisConnectionCreator: () => redisConnectionType, idlePoolSize?: number, nodeFSModule?: typeof fs, nodeCryptoModule?: typeof crypto);
19
+ initialize(): Promise<void>;
19
20
  generateUniqueToken(prefix: string): string;
20
21
  shutdown(): Promise<void>;
21
22
  acquire(token: string): Promise<void>;
@@ -32,6 +32,10 @@ class IORedisClientPool {
32
32
  this.redisConnectionCreator = redisConnectionCreator;
33
33
  this.idlePoolSize = idlePoolSize;
34
34
  }
35
+ initialize() {
36
+ // ioredis creates connection lazily on first command, so we don't need to do anything here.
37
+ return Promise.resolve();
38
+ }
35
39
  generateUniqueToken(prefix) {
36
40
  return `${prefix}-${this.nodeCryptoModule.randomUUID()}`;
37
41
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redis-abstraction",
3
- "version": "1.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "A Redis client pool with abstraction to different Redis libraries.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -13,7 +13,7 @@
13
13
  "clean-build:linux": "rm -rf ./dist/",
14
14
  "clean-build:windows": "rmdir /s /q .\\dist\\",
15
15
  "test-run": "nyc --reporter=html --reporter=text mocha -r ts-node/register ./tests/**/*.ts",
16
- "test": "npm run build && npm run test-run",
16
+ "test": "npm run build && npm run test-run && cd ./integration-test && npm install && npm run test && cd ..",
17
17
  "build": "(npm run clean-build || node -v) && tsc && npm run copy-files && npm run docs",
18
18
  "redisstop": "docker stop TestCentralStore && ping 127.0.0.1 -c 3",
19
19
  "redisstart": "(npm run redisstop || docker -v ) && docker run --name TestCentralStore -v ${PWD}:\"/var/lib/luatest\" -p 6379:6379 -itd --rm redis:latest",
@@ -93,16 +93,14 @@ class RedisClientPool {
93
93
  }
94
94
  pipeline(token, commands, transaction) {
95
95
  return __awaiter(this, void 0, void 0, function* () {
96
- var _a;
97
96
  const redisClient = this.activeRedisClients.get(token);
98
97
  if (redisClient == undefined) {
99
98
  throw new Error("Please acquire a client with proper token");
100
99
  }
101
100
  const transactionContext = redisClient.multi();
102
101
  for (const cmd of commands) {
103
- const commandName = ((_a = cmd.shift()) !== null && _a !== void 0 ? _a : "").toUpperCase();
104
102
  // @ts-ignore
105
- transactionContext[commandName](...cmd);
103
+ transactionContext.addCommand(cmd);
106
104
  }
107
105
  return transaction === true ? yield transactionContext.exec() : yield transactionContext.execAsPipeline();
108
106
  });