@hastehaul/common 2.0.50 → 2.0.51

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,13 +5,10 @@ export declare class RedisClient {
5
5
  get masterClient(): IORedis;
6
6
  get relicaClients(): IORedis[];
7
7
  connect(masterHost: string, replicaHosts: string[]): Promise<void>;
8
- private executeMasterOperation;
9
- private executeReplicaOperation;
10
- private executeOperation;
11
- set(key: string, value: string): Promise<any>;
12
- get(key: string): Promise<any>;
13
- del(key: string): Promise<any>;
14
- setex(key: string, value: string, seconds: number): Promise<any>;
8
+ set(key: string, value: any): Promise<'OK'>;
9
+ get(key: string): Promise<string | null>;
10
+ del(key: string): Promise<number>;
11
+ setex(key: string, seconds: number, value: string): Promise<'OK'>;
15
12
  quit(): void;
16
13
  }
17
14
  export declare const rWrapper: RedisClient;
@@ -1,27 +1,4 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
3
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
4
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -31,9 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
31
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
32
9
  });
33
10
  };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
34
14
  Object.defineProperty(exports, "__esModule", { value: true });
35
15
  exports.rWrapper = exports.RedisClient = void 0;
36
- const ioredis_1 = __importStar(require("ioredis"));
16
+ const ioredis_1 = __importDefault(require("ioredis"));
37
17
  class RedisClient {
38
18
  get masterClient() {
39
19
  if (!this.master)
@@ -76,35 +56,18 @@ class RedisClient {
76
56
  return console.log('All connections established');
77
57
  });
78
58
  }
79
- executeMasterOperation(command, ...args) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- return this.executeOperation(this.master, command, ...args);
82
- });
83
- }
84
- executeReplicaOperation(command, ...args) {
85
- return __awaiter(this, void 0, void 0, function* () {
86
- const replica = this.replicas[Math.floor(Math.random() * this.replicas.length)];
87
- return this.executeOperation(replica, command, ...args);
88
- });
89
- }
90
- executeOperation(client, command, ...args) {
91
- return __awaiter(this, void 0, void 0, function* () {
92
- return client.sendCommand(new ioredis_1.Command(command, args));
93
- });
94
- }
95
59
  set(key, value) {
96
- return this.executeMasterOperation('SET', key, value);
60
+ return this.master.set(key, value);
97
61
  }
98
62
  get(key) {
99
- return this.executeReplicaOperation('GET', key);
63
+ const replica = this.replicas[Math.floor(Math.random() * this.replicas.length)];
64
+ return replica.get(key);
100
65
  }
101
66
  del(key) {
102
- return this.executeMasterOperation('DEL', key);
67
+ return this.master.del(key);
103
68
  }
104
- setex(key, value, seconds) {
105
- return __awaiter(this, void 0, void 0, function* () {
106
- return this.executeMasterOperation('SETEX', key, seconds, value);
107
- });
69
+ setex(key, seconds, value) {
70
+ return this.master.setex(key, seconds, value);
108
71
  }
109
72
  quit() {
110
73
  this.master.quit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "2.0.50",
3
+ "version": "2.0.51",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",