deepbase-redis 1.0.22 → 1.1.0
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/demo/demo.mjs +7 -0
- package/index.js +30 -10
- package/package.json +1 -1
- package/test/test.mjs +11 -2
package/demo/demo.mjs
CHANGED
|
@@ -4,6 +4,9 @@ const mem = new DeepBase({ name: "demo" });
|
|
|
4
4
|
|
|
5
5
|
await mem.connect();
|
|
6
6
|
|
|
7
|
+
// Reset
|
|
8
|
+
await mem.del();
|
|
9
|
+
|
|
7
10
|
// SET
|
|
8
11
|
await mem.set("config", "lang", "en");
|
|
9
12
|
|
|
@@ -29,6 +32,10 @@ await mem.add("user", { name: "anya" });
|
|
|
29
32
|
const userIds = await mem.keys("user")
|
|
30
33
|
console.log(userIds) // [ 'CqtOILTDUg', 'MXOlTBSmEf' ]
|
|
31
34
|
|
|
35
|
+
const userValues = await mem.values("user")
|
|
36
|
+
console.log(userValues)
|
|
37
|
+
// [ { name: 'martin', count: 2 }, { name: 'anya' }]
|
|
38
|
+
|
|
32
39
|
// UPDATE
|
|
33
40
|
await mem.upd("config", "lang", v => v.toUpperCase());
|
|
34
41
|
const lang = await mem.get("config", "lang"); // EN
|
package/index.js
CHANGED
|
@@ -57,20 +57,12 @@ class DeepBaseRedis {
|
|
|
57
57
|
|
|
58
58
|
async get(...args) {
|
|
59
59
|
|
|
60
|
-
if (args.length
|
|
61
|
-
const scan = {
|
|
62
|
-
TYPE: 'ReJSON-RL',
|
|
63
|
-
MATCH: this.name + ':*',
|
|
64
|
-
COUNT: 10000,
|
|
65
|
-
}
|
|
60
|
+
if (args.length === 0) {
|
|
66
61
|
|
|
67
62
|
const dic = {}
|
|
68
|
-
for
|
|
69
|
-
console.log(key)
|
|
70
|
-
key = key.substring(this.name.length + 1)
|
|
63
|
+
for (let key of await this._zeroKeys()) {
|
|
71
64
|
dic[key] = await this.get(key);
|
|
72
65
|
}
|
|
73
|
-
|
|
74
66
|
return dic;
|
|
75
67
|
}
|
|
76
68
|
|
|
@@ -91,6 +83,11 @@ class DeepBaseRedis {
|
|
|
91
83
|
return (r !== null && typeof r === "object") ? Object.keys(r) : [];
|
|
92
84
|
}
|
|
93
85
|
|
|
86
|
+
async values(...args) {
|
|
87
|
+
const r = await this.get(...args)
|
|
88
|
+
return (r !== null && typeof r === "object") ? Object.values(r) : [];
|
|
89
|
+
}
|
|
90
|
+
|
|
94
91
|
async upd(...args) {
|
|
95
92
|
const func = args.pop()
|
|
96
93
|
return this.set(...args, func(await this.get(...args)))
|
|
@@ -117,7 +114,30 @@ class DeepBaseRedis {
|
|
|
117
114
|
return this.inc(...args)
|
|
118
115
|
}
|
|
119
116
|
|
|
117
|
+
async _zeroKeys() {
|
|
118
|
+
const scan = {
|
|
119
|
+
TYPE: 'ReJSON-RL',
|
|
120
|
+
MATCH: this.name + ':*',
|
|
121
|
+
COUNT: 1000,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const keys = []
|
|
125
|
+
for await (let key of this.client.scanIterator(scan)) {
|
|
126
|
+
keys.push(key.substring(this.name.length + 1));
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return keys;
|
|
130
|
+
}
|
|
131
|
+
|
|
120
132
|
async del(...args) {
|
|
133
|
+
|
|
134
|
+
if (args.length === 0) {
|
|
135
|
+
|
|
136
|
+
for (let key of await this._zeroKeys()) {
|
|
137
|
+
await this.del(key);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
121
141
|
const key = args.shift()
|
|
122
142
|
const path = args.length == 0 ? "." : args.join('.')
|
|
123
143
|
await this.client.json.del(this.name + ":" + key, path);
|
package/package.json
CHANGED
package/test/test.mjs
CHANGED
|
@@ -60,7 +60,7 @@ describe('DeepBaseRedis', () => {
|
|
|
60
60
|
await db.set('foo', 'bar', 'baz');
|
|
61
61
|
await db.set('qux', 'quux', 'corge');
|
|
62
62
|
assert.deepEqual(await db.get(), { foo: { bar: 'baz' }, qux: { quux: 'corge' } });
|
|
63
|
-
});
|
|
63
|
+
});
|
|
64
64
|
});
|
|
65
65
|
|
|
66
66
|
describe('#del()', () => {
|
|
@@ -127,6 +127,15 @@ describe('DeepBaseRedis', () => {
|
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
129
|
|
|
130
|
+
describe('#values()', () => {
|
|
131
|
+
|
|
132
|
+
it('should return values', async () => {
|
|
133
|
+
await db.set('foo', 'bar', 1);
|
|
134
|
+
await db.set('foo', 'quux', 1);
|
|
135
|
+
assert.deepEqual(await db.values('foo'), [1, 1]);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
130
139
|
describe('#upd()', async () => {
|
|
131
140
|
|
|
132
141
|
it('should update field keys', async () => {
|
|
@@ -136,5 +145,5 @@ describe('DeepBaseRedis', () => {
|
|
|
136
145
|
});
|
|
137
146
|
});
|
|
138
147
|
|
|
139
|
-
|
|
148
|
+
|
|
140
149
|
});
|