deepbase-redis 1.0.20 → 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/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # 🌳 DeepBase Redis
2
2
 
3
- DeepBaseRedis is an innovative and efficient module designed to seamlessly integrate with Redis Stack, providing a robust solution for managing and interacting with databases. With DeepBaseRedis, you can effortlessly perform CRUD operations and manipulate data stored in Redis Stack (json module) collections.
3
+ DeepBaseRedis is an innovative and efficient module designed to seamlessly integrate with Redis Stack, providing a robust solution for managing and interacting with databases. With DeepBaseRedis, you can effortlessly perform CRUD operations and manipulate data stored in Redis Stack (RedisJSON Module) keys.
4
4
 
5
5
  For simplicity you may be interested in the version of DeepBase that persists in JSON files. https://www.npmjs.com/package/deepbase
6
6
 
7
7
  ## 📦 Installation
8
8
  ```shell
9
- # DeepBaseRedis requires Redis Stack, which includes the necessary Redis JSON module. Here's how you can set it up:
9
+ # DeepBaseRedis requires Redis Stack, which includes the necessary RedisJSON module.
10
10
  docker run -d --name redis-stack-server -p 6379:6379 redis/redis-stack-server:latest
11
11
 
12
12
  npm install deepbase-redis
@@ -60,11 +60,7 @@ await mem.add("user", { name: "anya" });
60
60
  const userIds = await mem.keys("user")
61
61
  console.log(userIds) // [ 'CqtOILTDUg', 'MXOlTBSmEf' ]
62
62
 
63
- const result = {
64
- config: await mem.get('config'),
65
- user: await mem.get('user'),
66
- }
67
- console.log(result)
63
+ console.log(await mem.get())
68
64
  // {
69
65
  // config: { lang: 'EN' },
70
66
  // user: {
@@ -76,7 +72,7 @@ console.log(result)
76
72
 
77
73
  ## 🤯 Features
78
74
  - 🔍 Easily access and modify nested objects in JSON storage.
79
- - 📁 Provides an easy-to-use interface for connecting to Redis JSON and performing data operations, saving development.
75
+ - 📁 Provides an easy-to-use interface for connecting to RedisJSON and performing data operations, saving development.
80
76
  - 🌱 Simple and intuitive API for managing complex JSON structures.
81
77
 
82
78
  ## 🤔 Why DeepBase
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,14 +32,15 @@ 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
35
42
 
36
- console.log({
37
- config: await mem.get("config"),
38
- user: await mem.get("user")
39
- })
43
+ console.log(await mem.get())
40
44
 
41
45
  await mem.disconnect();
42
46
  // {
package/index.js CHANGED
@@ -57,7 +57,14 @@ class DeepBaseRedis {
57
57
 
58
58
  async get(...args) {
59
59
 
60
- if (args.length == 0) return null
60
+ if (args.length === 0) {
61
+
62
+ const dic = {}
63
+ for (let key of await this._zeroKeys()) {
64
+ dic[key] = await this.get(key);
65
+ }
66
+ return dic;
67
+ }
61
68
 
62
69
  const key = args.shift()
63
70
  const path = args.length == 0 ? "." : args.join('.');
@@ -76,6 +83,11 @@ class DeepBaseRedis {
76
83
  return (r !== null && typeof r === "object") ? Object.keys(r) : [];
77
84
  }
78
85
 
86
+ async values(...args) {
87
+ const r = await this.get(...args)
88
+ return (r !== null && typeof r === "object") ? Object.values(r) : [];
89
+ }
90
+
79
91
  async upd(...args) {
80
92
  const func = args.pop()
81
93
  return this.set(...args, func(await this.get(...args)))
@@ -102,7 +114,30 @@ class DeepBaseRedis {
102
114
  return this.inc(...args)
103
115
  }
104
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
+
105
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
+
106
141
  const key = args.shift()
107
142
  const path = args.length == 0 ? "." : args.join('.')
108
143
  await this.client.json.del(this.name + ":" + key, path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepbase-redis",
3
- "version": "1.0.20",
3
+ "version": "1.1.0",
4
4
  "description": "⚡ Fastest and simplest way to add Redis Stack persistence to your projects.",
5
5
  "main": "index.js",
6
6
  "dependencies": {
package/test/test.mjs CHANGED
@@ -56,8 +56,10 @@ describe('DeepBaseRedis', () => {
56
56
  assert.deepEqual(await db.get('foo', 'bar'), null);
57
57
  });
58
58
 
59
- it('should return null if no keys are provided', async () => {
60
- assert.deepEqual(await db.get(), null);
59
+ it('should return the entire database if no keys are provided', async () => {
60
+ await db.set('foo', 'bar', 'baz');
61
+ await db.set('qux', 'quux', 'corge');
62
+ assert.deepEqual(await db.get(), { foo: { bar: 'baz' }, qux: { quux: 'corge' } });
61
63
  });
62
64
  });
63
65
 
@@ -125,6 +127,15 @@ describe('DeepBaseRedis', () => {
125
127
  });
126
128
  });
127
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
+
128
139
  describe('#upd()', async () => {
129
140
 
130
141
  it('should update field keys', async () => {
@@ -134,5 +145,5 @@ describe('DeepBaseRedis', () => {
134
145
  });
135
146
  });
136
147
 
137
-
148
+
138
149
  });