deepbase-redis 3.6.5 → 3.6.7
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/package.json +2 -2
- package/src/RedisDriver.js +31 -0
- package/test/test.js +47 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepbase-redis",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.7",
|
|
4
4
|
"description": "⚡ DeepBase Redis (vanilla) - driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.cjs",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"redis": "^4.7.0"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"deepbase": "^3.6.
|
|
20
|
+
"deepbase": "^3.6.7"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"test": "mocha test/test.js"
|
package/src/RedisDriver.js
CHANGED
|
@@ -195,6 +195,37 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
195
195
|
const func = args.pop();
|
|
196
196
|
return this.set(...args, func(await this.get(...args)));
|
|
197
197
|
}
|
|
198
|
+
|
|
199
|
+
async first(...args) {
|
|
200
|
+
const value = await this.get(...args);
|
|
201
|
+
if (value === null || typeof value !== 'object') {
|
|
202
|
+
return undefined;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
for (const key in value) {
|
|
206
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
207
|
+
return key;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async last(...args) {
|
|
215
|
+
const value = await this.get(...args);
|
|
216
|
+
if (value === null || typeof value !== 'object') {
|
|
217
|
+
return undefined;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
let last;
|
|
221
|
+
for (const key in value) {
|
|
222
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
223
|
+
last = key;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return last;
|
|
228
|
+
}
|
|
198
229
|
|
|
199
230
|
async _zeroKeys() {
|
|
200
231
|
const scan = {
|
package/test/test.js
CHANGED
|
@@ -5,11 +5,34 @@ import { RedisDriver } from '../src/RedisDriver.js';
|
|
|
5
5
|
describe('RedisDriver', function() {
|
|
6
6
|
let db;
|
|
7
7
|
let testCounter = 0;
|
|
8
|
+
let redisAvailable = true;
|
|
9
|
+
let redisSkipReason = '';
|
|
8
10
|
|
|
9
11
|
// Increase timeout for Redis operations
|
|
10
12
|
this.timeout(10000);
|
|
11
13
|
|
|
14
|
+
before(async function() {
|
|
15
|
+
const probeDb = new DeepBase(new RedisDriver({
|
|
16
|
+
url: 'redis://localhost:6379',
|
|
17
|
+
prefix: '__availability_probe__'
|
|
18
|
+
}));
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await probeDb.connect();
|
|
22
|
+
await probeDb.disconnect();
|
|
23
|
+
} catch (error) {
|
|
24
|
+
redisAvailable = false;
|
|
25
|
+
redisSkipReason = error?.message || 'Unknown Redis connection error';
|
|
26
|
+
console.warn(`[deepbase-redis:test] Redis is unavailable, skipping tests: ${redisSkipReason}`);
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
|
|
12
30
|
beforeEach(async function() {
|
|
31
|
+
if (!redisAvailable) {
|
|
32
|
+
this.skip();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
13
36
|
testCounter++;
|
|
14
37
|
db = new DeepBase(new RedisDriver({
|
|
15
38
|
url: 'redis://localhost:6379',
|
|
@@ -19,7 +42,7 @@ describe('RedisDriver', function() {
|
|
|
19
42
|
try {
|
|
20
43
|
await db.connect();
|
|
21
44
|
} catch (error) {
|
|
22
|
-
this.skip();
|
|
45
|
+
this.skip();
|
|
23
46
|
}
|
|
24
47
|
});
|
|
25
48
|
|
|
@@ -169,6 +192,16 @@ describe('RedisDriver', function() {
|
|
|
169
192
|
assert.strictEqual(user.age, undefined);
|
|
170
193
|
});
|
|
171
194
|
|
|
195
|
+
it('should delete a deep key from an object value', async function() {
|
|
196
|
+
await db.set('a', {
|
|
197
|
+
b: { c: 1, d: 2 },
|
|
198
|
+
e: 3
|
|
199
|
+
});
|
|
200
|
+
await db.del('a', 'b', 'c');
|
|
201
|
+
|
|
202
|
+
assert.deepStrictEqual(await db.get('a'), { b: { d: 2 }, e: 3 });
|
|
203
|
+
});
|
|
204
|
+
|
|
172
205
|
it('should clear all data', async function() {
|
|
173
206
|
await db.set('key1', 'value1');
|
|
174
207
|
await db.set('key2', 'value2');
|
|
@@ -306,6 +339,19 @@ describe('RedisDriver', function() {
|
|
|
306
339
|
assert.ok(entries.some(([k, v]) => k === 'alice' && v.age === 30));
|
|
307
340
|
assert.ok(entries.some(([k, v]) => k === 'bob' && v.age === 25));
|
|
308
341
|
});
|
|
342
|
+
|
|
343
|
+
it('first/last should match keys() boundaries', async function() {
|
|
344
|
+
const keys = await db.keys('users');
|
|
345
|
+
const driver = db.getDriver(0);
|
|
346
|
+
assert.strictEqual(await driver.first('users'), keys[0]);
|
|
347
|
+
assert.strictEqual(await driver.last('users'), keys[keys.length - 1]);
|
|
348
|
+
});
|
|
349
|
+
|
|
350
|
+
it('first/last should return undefined for missing path', async function() {
|
|
351
|
+
const driver = db.getDriver(0);
|
|
352
|
+
assert.strictEqual(await driver.first('missing'), undefined);
|
|
353
|
+
assert.strictEqual(await driver.last('missing'), undefined);
|
|
354
|
+
});
|
|
309
355
|
});
|
|
310
356
|
|
|
311
357
|
describe('Complex Nested Operations', function() {
|