deepbase-redis 3.0.6 → 3.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/package.json +2 -2
- package/src/RedisDriver.js +6 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepbase-redis",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "⚡ DeepBase Redis Stack - driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.cjs",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"redis": "^4.7.0"
|
|
16
16
|
},
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"deepbase": "^3.0
|
|
18
|
+
"deepbase": "^3.1.0"
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
21
21
|
"test": "mocha test/test.js"
|
package/src/RedisDriver.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DeepBaseDriver } from 'deepbase';
|
|
2
2
|
import { createClient } from 'redis';
|
|
3
|
-
import { customAlphabet } from 'nanoid';
|
|
4
3
|
|
|
5
4
|
export class RedisDriver extends DeepBaseDriver {
|
|
6
5
|
constructor({name, prefix, url, ...opts} = {}) {
|
|
@@ -9,8 +8,6 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
9
8
|
this.name = name || prefix || "db";
|
|
10
9
|
this.url = url || "redis://localhost:6379";
|
|
11
10
|
|
|
12
|
-
this.nanoid = customAlphabet(this.nidAlphabet, this.nidLength);
|
|
13
|
-
|
|
14
11
|
this.client = createClient({ url: this.url });
|
|
15
12
|
}
|
|
16
13
|
|
|
@@ -33,7 +30,7 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
33
30
|
}
|
|
34
31
|
|
|
35
32
|
const key = args.shift();
|
|
36
|
-
const path = args.length == 0 ? "." :
|
|
33
|
+
const path = args.length == 0 ? "." : this._pathToKey(args);
|
|
37
34
|
|
|
38
35
|
try {
|
|
39
36
|
return await this.client.json.get(this.name + ":" + key, { path });
|
|
@@ -49,7 +46,7 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
49
46
|
const value = args[args.length - 1];
|
|
50
47
|
|
|
51
48
|
const key = keys.shift();
|
|
52
|
-
const keyPath = keys.length == 0 ? "." :
|
|
49
|
+
const keyPath = keys.length == 0 ? "." : this._pathToKey(keys);
|
|
53
50
|
await this._set(key, keyPath, value);
|
|
54
51
|
|
|
55
52
|
return args.slice(0, -1);
|
|
@@ -58,7 +55,7 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
58
55
|
async inc(...args) {
|
|
59
56
|
const i = args.pop();
|
|
60
57
|
const key = args.shift();
|
|
61
|
-
const path = args.length == 0 ? "." :
|
|
58
|
+
const path = args.length == 0 ? "." : this._pathToKey(args);
|
|
62
59
|
|
|
63
60
|
try {
|
|
64
61
|
await this.client.json.numIncrBy(this.name + ":" + key, path, i);
|
|
@@ -84,7 +81,7 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
84
81
|
}
|
|
85
82
|
|
|
86
83
|
const key = args.shift();
|
|
87
|
-
const path = args.length == 0 ? "." :
|
|
84
|
+
const path = args.length == 0 ? "." : this._pathToKey(args);
|
|
88
85
|
await this.client.json.del(this.name + ":" + key, path);
|
|
89
86
|
|
|
90
87
|
return [key, ...args];
|
|
@@ -111,9 +108,9 @@ export class RedisDriver extends DeepBaseDriver {
|
|
|
111
108
|
try {
|
|
112
109
|
await this.client.json.set(this.name + ":" + key, path, value);
|
|
113
110
|
} catch (error) {
|
|
114
|
-
const keys =
|
|
111
|
+
const keys = this._keyToPath(path);
|
|
115
112
|
keys.pop();
|
|
116
|
-
const keyPath = keys.length == 0 ? "." :
|
|
113
|
+
const keyPath = keys.length == 0 ? "." : this._pathToKey(keys);
|
|
117
114
|
await this._set(key, keyPath, {});
|
|
118
115
|
await this._set(key, path, value);
|
|
119
116
|
}
|