@onlineapps/conn-base-cache 1.0.8 → 1.0.9
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.
package/API.md
CHANGED
|
@@ -69,7 +69,7 @@ Redis cache connector providing caching operations with automatic key management
|
|
|
69
69
|
**Example** *(Basic Usage)*
|
|
70
70
|
```js
|
|
71
71
|
const cache = new CacheConnector({
|
|
72
|
-
host: '
|
|
72
|
+
host: '127.0.0.1',
|
|
73
73
|
port: 6379,
|
|
74
74
|
defaultTTL: 3600
|
|
75
75
|
});
|
|
@@ -97,7 +97,7 @@ Creates a new CacheConnector instance
|
|
|
97
97
|
| Param | Type | Default | Description |
|
|
98
98
|
| --- | --- | --- | --- |
|
|
99
99
|
| [config] | <code>Object</code> | <code>{}</code> | Configuration options |
|
|
100
|
-
| [config.host] | <code>string</code> |
|
|
100
|
+
| [config.host] | <code>string</code> | | Redis server host (**required** via config or env: <code>REDIS_HOST</code>) |
|
|
101
101
|
| [config.port] | <code>number</code> | <code>6379</code> | Redis server port |
|
|
102
102
|
| [config.password] | <code>string</code> | | Redis password for authentication |
|
|
103
103
|
| [config.db] | <code>number</code> | <code>0</code> | Redis database number to use |
|
|
@@ -137,7 +137,7 @@ Redis cache connector providing caching operations with automatic key management
|
|
|
137
137
|
**Example** *(Basic Usage)*
|
|
138
138
|
```js
|
|
139
139
|
const cache = new CacheConnector({
|
|
140
|
-
host: '
|
|
140
|
+
host: '127.0.0.1',
|
|
141
141
|
port: 6379,
|
|
142
142
|
defaultTTL: 3600
|
|
143
143
|
});
|
|
@@ -165,7 +165,7 @@ Creates a new CacheConnector instance
|
|
|
165
165
|
| Param | Type | Default | Description |
|
|
166
166
|
| --- | --- | --- | --- |
|
|
167
167
|
| [config] | <code>Object</code> | <code>{}</code> | Configuration options |
|
|
168
|
-
| [config.host] | <code>string</code> |
|
|
168
|
+
| [config.host] | <code>string</code> | | Redis server host (**required** via config or env: <code>REDIS_HOST</code>) |
|
|
169
169
|
| [config.port] | <code>number</code> | <code>6379</code> | Redis server port |
|
|
170
170
|
| [config.password] | <code>string</code> | | Redis password for authentication |
|
|
171
171
|
| [config.db] | <code>number</code> | <code>0</code> | Redis database number to use |
|
|
@@ -652,7 +652,7 @@ Factory function to create cache instance
|
|
|
652
652
|
**Example**
|
|
653
653
|
```js
|
|
654
654
|
const cache = CacheConnector.create({
|
|
655
|
-
host: '
|
|
655
|
+
host: '127.0.0.1',
|
|
656
656
|
namespace: 'my-service'
|
|
657
657
|
});
|
|
658
658
|
```
|
|
@@ -664,7 +664,7 @@ const cache = CacheConnector.create({
|
|
|
664
664
|
|
|
665
665
|
| Name | Type | Default | Description |
|
|
666
666
|
| --- | --- | --- | --- |
|
|
667
|
-
| [host] | <code>string</code> |
|
|
667
|
+
| [host] | <code>string</code> | | Redis host (**required**) |
|
|
668
668
|
| [port] | <code>number</code> | <code>6379</code> | Redis port |
|
|
669
669
|
| [password] | <code>string</code> | | Redis password |
|
|
670
670
|
| [db] | <code>number</code> | <code>0</code> | Redis database |
|
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npm install @onlineapps/conn-base-cache
|
|
|
25
25
|
const CacheConnector = require('@onlineapps/conn-base-cache');
|
|
26
26
|
|
|
27
27
|
const cache = new CacheConnector({
|
|
28
|
-
host: '
|
|
28
|
+
host: '127.0.0.1',
|
|
29
29
|
port: 6379,
|
|
30
30
|
defaultTTL: 3600, // 1 hour
|
|
31
31
|
namespace: 'invoice-service'
|
|
@@ -51,8 +51,8 @@ console.log(cache.getStats());
|
|
|
51
51
|
|
|
52
52
|
| Option | Environment Variable | Default | Description |
|
|
53
53
|
|--------|---------------------|---------|-------------|
|
|
54
|
-
| `host` | `REDIS_HOST` |
|
|
55
|
-
| `port` | `REDIS_PORT` |
|
|
54
|
+
| `host` | `REDIS_HOST` | **(required)** | Redis server host |
|
|
55
|
+
| `port` | `REDIS_PORT` | **(required)** | Redis server port |
|
|
56
56
|
| `password` | `REDIS_PASSWORD` | - | Redis password |
|
|
57
57
|
| `db` | `REDIS_DB` | `0` | Redis database number |
|
|
58
58
|
| `defaultTTL` | - | `3600` | Default TTL in seconds |
|
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -184,10 +184,9 @@ class CacheConnector {
|
|
|
184
184
|
return Math.min(times * this.config.retryDelay, 2000);
|
|
185
185
|
},
|
|
186
186
|
enableOfflineQueue: this.config.enableOfflineQueue,
|
|
187
|
-
lazyConnect:
|
|
187
|
+
lazyConnect: true
|
|
188
188
|
});
|
|
189
189
|
|
|
190
|
-
// Handle events
|
|
191
190
|
this.client.on('connect', () => {
|
|
192
191
|
this.connected = true;
|
|
193
192
|
this.connecting = false;
|
|
@@ -204,10 +203,7 @@ class CacheConnector {
|
|
|
204
203
|
console.log('Redis cache connection closed');
|
|
205
204
|
});
|
|
206
205
|
|
|
207
|
-
|
|
208
|
-
if (!this.config.lazyConnect) {
|
|
209
|
-
await this.client.connect();
|
|
210
|
-
}
|
|
206
|
+
await this.client.connect();
|
|
211
207
|
|
|
212
208
|
this.connected = true;
|
|
213
209
|
this.connecting = false;
|
|
@@ -118,7 +118,7 @@ describe('CacheConnector - Component Tests @component', () => {
|
|
|
118
118
|
|
|
119
119
|
// Inject Redis simulator
|
|
120
120
|
cacheConnector = new CacheConnector({
|
|
121
|
-
host: '
|
|
121
|
+
host: '127.0.0.1',
|
|
122
122
|
port: 6379,
|
|
123
123
|
namespace: 'test-service',
|
|
124
124
|
defaultTTL: 60
|
|
@@ -201,6 +201,8 @@ describe('CacheConnector - Component Tests @component', () => {
|
|
|
201
201
|
|
|
202
202
|
// Second service with different namespace
|
|
203
203
|
const cache2 = new CacheConnector({
|
|
204
|
+
host: '127.0.0.1',
|
|
205
|
+
port: 6379,
|
|
204
206
|
namespace: 'other-service'
|
|
205
207
|
});
|
|
206
208
|
cache2.client = redisSimulator;
|
|
@@ -152,7 +152,7 @@ describe('CacheConnector - Edge Cases & Full Coverage @unit', () => {
|
|
|
152
152
|
|
|
153
153
|
describe('Data Type Edge Cases', () => {
|
|
154
154
|
beforeEach(async () => {
|
|
155
|
-
cacheConnector = new CacheConnector({ host: '
|
|
155
|
+
cacheConnector = new CacheConnector({ host: '127.0.0.1', port: 6379 });
|
|
156
156
|
await cacheConnector.connect();
|
|
157
157
|
});
|
|
158
158
|
|
|
@@ -112,7 +112,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
112
112
|
describe('connect', () => {
|
|
113
113
|
beforeEach(() => {
|
|
114
114
|
cacheConnector = new CacheConnector({
|
|
115
|
-
host: '
|
|
115
|
+
host: '127.0.0.1',
|
|
116
116
|
port: 6379,
|
|
117
117
|
namespace: 'test-service'
|
|
118
118
|
});
|
|
@@ -123,7 +123,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
123
123
|
|
|
124
124
|
expect(Redis).toHaveBeenCalledWith(
|
|
125
125
|
expect.objectContaining({
|
|
126
|
-
host: '
|
|
126
|
+
host: '127.0.0.1',
|
|
127
127
|
port: 6379,
|
|
128
128
|
keyPrefix: 'cache:'
|
|
129
129
|
})
|
|
@@ -160,7 +160,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
160
160
|
describe('disconnect', () => {
|
|
161
161
|
beforeEach(async () => {
|
|
162
162
|
cacheConnector = new CacheConnector({
|
|
163
|
-
host: '
|
|
163
|
+
host: '127.0.0.1',
|
|
164
164
|
port: 6379,
|
|
165
165
|
namespace: 'test-service'
|
|
166
166
|
});
|
|
@@ -188,7 +188,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
188
188
|
describe('get', () => {
|
|
189
189
|
beforeEach(async () => {
|
|
190
190
|
cacheConnector = new CacheConnector({
|
|
191
|
-
host: '
|
|
191
|
+
host: '127.0.0.1',
|
|
192
192
|
port: 6379,
|
|
193
193
|
namespace: 'test-service'
|
|
194
194
|
});
|
|
@@ -245,7 +245,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
245
245
|
describe('set', () => {
|
|
246
246
|
beforeEach(async () => {
|
|
247
247
|
cacheConnector = new CacheConnector({
|
|
248
|
-
host: '
|
|
248
|
+
host: '127.0.0.1',
|
|
249
249
|
port: 6379,
|
|
250
250
|
namespace: 'test-service',
|
|
251
251
|
defaultTTL: 3600
|
|
@@ -314,7 +314,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
314
314
|
describe('delete', () => {
|
|
315
315
|
beforeEach(async () => {
|
|
316
316
|
cacheConnector = new CacheConnector({
|
|
317
|
-
host: '
|
|
317
|
+
host: '127.0.0.1',
|
|
318
318
|
port: 6379,
|
|
319
319
|
namespace: 'test-service'
|
|
320
320
|
});
|
|
@@ -351,7 +351,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
351
351
|
describe('deleteByPattern', () => {
|
|
352
352
|
beforeEach(async () => {
|
|
353
353
|
cacheConnector = new CacheConnector({
|
|
354
|
-
host: '
|
|
354
|
+
host: '127.0.0.1',
|
|
355
355
|
port: 6379,
|
|
356
356
|
namespace: 'test-service'
|
|
357
357
|
});
|
|
@@ -396,7 +396,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
396
396
|
describe('exists', () => {
|
|
397
397
|
beforeEach(async () => {
|
|
398
398
|
cacheConnector = new CacheConnector({
|
|
399
|
-
host: '
|
|
399
|
+
host: '127.0.0.1',
|
|
400
400
|
port: 6379,
|
|
401
401
|
namespace: 'test-service'
|
|
402
402
|
});
|
|
@@ -431,7 +431,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
431
431
|
describe('ttl', () => {
|
|
432
432
|
beforeEach(async () => {
|
|
433
433
|
cacheConnector = new CacheConnector({
|
|
434
|
-
host: '
|
|
434
|
+
host: '127.0.0.1',
|
|
435
435
|
port: 6379,
|
|
436
436
|
namespace: 'test-service'
|
|
437
437
|
});
|
|
@@ -474,7 +474,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
474
474
|
describe('expire', () => {
|
|
475
475
|
beforeEach(async () => {
|
|
476
476
|
cacheConnector = new CacheConnector({
|
|
477
|
-
host: '
|
|
477
|
+
host: '127.0.0.1',
|
|
478
478
|
port: 6379,
|
|
479
479
|
namespace: 'test-service'
|
|
480
480
|
});
|
|
@@ -509,7 +509,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
509
509
|
describe('incr/decr', () => {
|
|
510
510
|
beforeEach(async () => {
|
|
511
511
|
cacheConnector = new CacheConnector({
|
|
512
|
-
host: '
|
|
512
|
+
host: '127.0.0.1',
|
|
513
513
|
port: 6379,
|
|
514
514
|
namespace: 'test-service'
|
|
515
515
|
});
|
|
@@ -650,7 +650,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
650
650
|
describe('flush', () => {
|
|
651
651
|
beforeEach(async () => {
|
|
652
652
|
cacheConnector = new CacheConnector({
|
|
653
|
-
host: '
|
|
653
|
+
host: '127.0.0.1',
|
|
654
654
|
port: 6379,
|
|
655
655
|
namespace: 'test-service'
|
|
656
656
|
});
|
|
@@ -755,7 +755,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
755
755
|
|
|
756
756
|
describe('healthCheck', () => {
|
|
757
757
|
beforeEach(async () => {
|
|
758
|
-
cacheConnector = new CacheConnector({ host: '
|
|
758
|
+
cacheConnector = new CacheConnector({ host: '127.0.0.1', port: 6379 });
|
|
759
759
|
await cacheConnector.connect();
|
|
760
760
|
});
|
|
761
761
|
|
|
@@ -797,7 +797,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
797
797
|
|
|
798
798
|
describe('withNamespace', () => {
|
|
799
799
|
it('should create new instance with combined namespace', async () => {
|
|
800
|
-
const cache1 = new CacheConnector({ host: '
|
|
800
|
+
const cache1 = new CacheConnector({ host: '127.0.0.1', port: 6379, namespace: 'service1' });
|
|
801
801
|
const cache2 = cache1.withNamespace('subsection');
|
|
802
802
|
|
|
803
803
|
expect(cache2).toBeInstanceOf(CacheConnector);
|
|
@@ -809,7 +809,7 @@ describe('CacheConnector - Unit Tests @unit', () => {
|
|
|
809
809
|
|
|
810
810
|
describe('wrap function', () => {
|
|
811
811
|
beforeEach(async () => {
|
|
812
|
-
cacheConnector = new CacheConnector({ host: '
|
|
812
|
+
cacheConnector = new CacheConnector({ host: '127.0.0.1', port: 6379, namespace: 'test' });
|
|
813
813
|
await cacheConnector.connect();
|
|
814
814
|
});
|
|
815
815
|
|