deepbase-redis 1.0.18 → 1.0.22

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
@@ -1,4 +1,4 @@
1
- import DeepBase from "../index.mjs";
1
+ import DeepBase from "../index.js";
2
2
 
3
3
  const mem = new DeepBase({ name: "demo" });
4
4
 
@@ -33,10 +33,7 @@ console.log(userIds) // [ 'CqtOILTDUg', 'MXOlTBSmEf' ]
33
33
  await mem.upd("config", "lang", v => v.toUpperCase());
34
34
  const lang = await mem.get("config", "lang"); // EN
35
35
 
36
- console.log({
37
- config: await mem.get("config"),
38
- user: await mem.get("user")
39
- })
36
+ console.log(await mem.get())
40
37
 
41
38
  await mem.disconnect();
42
39
  // {
@@ -1,7 +1,7 @@
1
- import { createClient } from 'redis';
2
- import { customAlphabet } from 'nanoid'
1
+ const { createClient } = require('redis');
2
+ const { customAlphabet } = require('nanoid');
3
3
 
4
- export default class DeepBaseRedis {
4
+ class DeepBaseRedis {
5
5
 
6
6
  constructor(opts = {}) {
7
7
  this.nidAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -57,7 +57,22 @@ export default class DeepBaseRedis {
57
57
 
58
58
  async get(...args) {
59
59
 
60
- if (args.length == 0) return null
60
+ if (args.length == 0) {
61
+ const scan = {
62
+ TYPE: 'ReJSON-RL',
63
+ MATCH: this.name + ':*',
64
+ COUNT: 10000,
65
+ }
66
+
67
+ const dic = {}
68
+ for await (let key of this.client.scanIterator(scan)) {
69
+ console.log(key)
70
+ key = key.substring(this.name.length + 1)
71
+ dic[key] = await this.get(key);
72
+ }
73
+
74
+ return dic;
75
+ }
61
76
 
62
77
  const key = args.shift()
63
78
  const path = args.length == 0 ? "." : args.join('.');
@@ -115,4 +130,6 @@ export default class DeepBaseRedis {
115
130
  await this.set(...[...keys, id, value])
116
131
  return [...keys, id]
117
132
  }
118
- }
133
+ }
134
+
135
+ module.exports = DeepBaseRedis;
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "deepbase-redis",
3
- "version": "1.0.18",
3
+ "version": "1.0.22",
4
4
  "description": "⚡ Fastest and simplest way to add Redis Stack persistence to your projects.",
5
- "main": "index.mjs",
5
+ "main": "index.js",
6
6
  "dependencies": {
7
- "nanoid": "^5.0.4",
7
+ "nanoid": "^3.3.4",
8
8
  "redis": "^4.6.12"
9
9
  },
10
10
  "scripts": {
package/test/test.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /* eslint-env mocha */
2
2
 
3
- import DeepBase from '../index.mjs';
3
+ import DeepBase from '../index.js';
4
4
  import assert from 'assert';
5
5
 
6
6
  describe('DeepBaseRedis', () => {
@@ -56,9 +56,11 @@ 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);
61
- });
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' } });
63
+ });
62
64
  });
63
65
 
64
66
  describe('#del()', () => {