ueberdb2 3.0.1 → 4.0.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/CHANGELOG.md CHANGED
@@ -1,11 +1,31 @@
1
1
  # Notable Changes
2
2
 
3
+ ## v4.0.0
4
+
5
+ Compatibility changes:
6
+
7
+ * `redis`: The `socket` and `client_options` settings, deprecated since
8
+ v1.3.1, have been removed.
9
+ * `redis`: The client configuration object has changed with the new version of
10
+ the `redis` client library. See the [`redis` client library
11
+ documentation](https://github.com/redis/node-redis/blob/redis%404.1.0/docs/client-configuration.md)
12
+ for details.
13
+
14
+ Bug fixes:
15
+
16
+ * `redis`: Several `findKeys()` fixes.
17
+
18
+ Updated database dependencies:
19
+
20
+ * `redis`: Updated `redis` from 3.1.2 to 4.1.0.
21
+
3
22
  ## v3.0.1
4
23
 
5
24
  Bug fixes:
6
25
 
7
26
  * Fixed `findKeys()` calls containing special regular expression characters
8
- for those database drivers that use the glob-to-regex helper function.
27
+ (applicable to the database drivers that use the glob-to-regex helper
28
+ function).
9
29
 
10
30
  ## v3.0.0
11
31
 
@@ -17,8 +37,12 @@ Compatibility changes:
17
37
  the `migrate_to_newer_schema` option to `true`.
18
38
  * As mentioned in the v2.2.0 changes, passing callbacks to the database
19
39
  methods is deprecated. Use the returned Promises instead.
20
- * As mentioned in the v1.4.15 changes, `postgrespool` is deprecated. Use
21
- `postgres` instead.
40
+ * `postgrespool`: As mentioned in the v1.4.15 changes, `postgrespool` is
41
+ deprecated. Use `postgres` instead.
42
+ * `redis`: As mentioned in the v1.3.1 changes, the `socket` and
43
+ `client_options` settings are deprecated. Pass the [client options
44
+ object](https://www.npmjs.com/package/redis/v/3.1.2#options-object-properties)
45
+ directly.
22
46
 
23
47
  Bug fixes:
24
48
 
package/README.md CHANGED
@@ -272,16 +272,8 @@ You should create your database as utf8mb4_bin.
272
272
  If you enabled TLS on your Redis database (available since Redis 6.0) you will
273
273
  need to change your connections parameters, here is an example:
274
274
 
275
- ```
276
- settings:
277
- {
278
- host:
279
- port: rediss://<redis_database_address>:<redis_database_port>
280
- socket:
281
- database:
282
- password:
283
- client_options
284
- }
275
+ ```javascript
276
+ const db = new ueberdb.Database('redis', {url: 'rediss://localhost'});
285
277
  ```
286
278
 
287
279
  Do not provide a `host` value.
@@ -1,5 +1,4 @@
1
1
  'use strict';
2
- /* eslint new-cap: ["error", {"capIsNewExceptions": ["KEYS", "SMEMBERS"]}] */
3
2
 
4
3
  /**
5
4
  * 2011 Peter 'Pita' Martischka
@@ -18,111 +17,80 @@
18
17
  */
19
18
 
20
19
  const AbstractDatabase = require('../lib/AbstractDatabase');
21
- const async = require('async');
22
20
  const redis = require('redis');
23
21
 
24
22
  exports.Database = class extends AbstractDatabase {
25
23
  constructor(settings) {
26
24
  super();
27
- this.client = null;
25
+ this._client = null;
28
26
  this.settings = settings || {};
29
27
  }
30
28
 
31
- auth(callback) {
32
- if (!this.settings.password) return callback();
33
- this.client.auth(this.settings.password, callback);
34
- }
35
-
36
- select(callback) {
37
- if (!this.settings.database) return callback();
38
- this.client.select(this.settings.database, callback);
39
- }
29
+ get isAsync() { return true; }
40
30
 
41
- _deprecatedInit(callback) {
42
- if (this.settings.socket) {
43
- // Deprecated, but kept for backwards compatibility.
44
- this.client = redis.createClient(this.settings.socket,
45
- this.settings.client_options);
46
- } else {
47
- // Deprecated, but kept for backwards compatibility.
48
- this.client = redis.createClient(this.settings.port,
49
- this.settings.host, this.settings.client_options);
50
- }
51
-
52
- this.client.database = this.settings.database;
53
- async.waterfall([this.auth.bind(this), this.select.bind(this)], callback);
31
+ async init() {
32
+ this._client = redis.createClient(this.settings);
33
+ await this._client.connect();
34
+ await this._client.ping();
54
35
  }
55
36
 
56
- init(callback) {
57
- if (this.settings.socket || this.settings.client_options) return this._deprecatedInit(callback);
58
- this.client = redis.createClient(this.settings);
59
- callback();
37
+ async get(key) {
38
+ return await this._client.get(key);
60
39
  }
61
40
 
62
- get(key, callback) {
63
- this.client.get(key, callback);
64
- }
65
-
66
- findKeys(key, notKey, callback) {
67
- // As redis provides only limited support for getting a list of all
68
- // available keys we have to limit key and notKey here.
69
- // See http://redis.io/commands/keys
70
- if (notKey == null) {
71
- this.client.KEYS(key, callback);
72
- } else if (notKey === '*:*:*') {
73
- // restrict key to format "text:*"
74
- const matches = /^([^:]+):\*$/.exec(key);
75
- if (matches) {
76
- this.client.SMEMBERS(`ueberDB:keys:${matches[1]}`, callback);
77
- } else {
78
- const msg = 'redis db only supports key patterns like pad:* when notKey is set to *:*:*';
79
- callback(new Error(msg), null);
80
- }
81
- } else {
82
- callback(new Error('redis db currently only supports *:*:* as notKey'), null);
41
+ async findKeys(key, notKey) {
42
+ const [type] = /^([^:*]+):\*$/.exec(key) || [];
43
+ if (type != null && ['*:*:*', `${key}:*`].includes(notKey)) {
44
+ // Performance optimization for a common Etherpad case.
45
+ return await this._client.sMembers(`ueberDB:keys:${type}`);
46
+ }
47
+ let keys = await this._client.keys(key.replace(/[?[\]\\]/g, '\\$&'));
48
+ if (notKey != null) {
49
+ const regex = this.createFindRegex(key, notKey);
50
+ keys = keys.filter((k) => regex.test(k));
83
51
  }
52
+ return keys;
84
53
  }
85
54
 
86
- set(key, value, callback) {
55
+ async set(key, value) {
87
56
  const matches = /^([^:]+):([^:]+)$/.exec(key);
88
- if (matches) {
89
- this.client.sadd([`ueberDB:keys:${matches[1]}`, matches[0]]);
90
- }
91
- this.client.set(key, value, callback);
57
+ await Promise.all([
58
+ matches && this._client.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]),
59
+ this._client.set(key, value),
60
+ ]);
92
61
  }
93
62
 
94
- remove(key, callback) {
63
+ async remove(key) {
95
64
  const matches = /^([^:]+):([^:]+)$/.exec(key);
96
- if (matches) {
97
- this.client.srem([`ueberDB:keys:${matches[1]}`, matches[0]]);
98
- }
99
- this.client.del(key, callback);
65
+ await Promise.all([
66
+ matches && this._client.sRem(`ueberDB:keys:${matches[1]}`, matches[0]),
67
+ this._client.del(key),
68
+ ]);
100
69
  }
101
70
 
102
- doBulk(bulk, callback) {
103
- const multi = this.client.multi();
71
+ async doBulk(bulk) {
72
+ const multi = this._client.multi();
104
73
 
105
74
  for (const {key, type, value} of bulk) {
106
75
  const matches = /^([^:]+):([^:]+)$/.exec(key);
107
76
  if (type === 'set') {
108
77
  if (matches) {
109
- multi.sadd([`ueberDB:keys:${matches[1]}`, matches[0]]);
78
+ multi.sAdd(`ueberDB:keys:${matches[1]}`, matches[0]);
110
79
  }
111
80
  multi.set(key, value);
112
81
  } else if (type === 'remove') {
113
82
  if (matches) {
114
- multi.srem([`ueberDB:keys:${matches[1]}`, matches[0]]);
83
+ multi.sRem(`ueberDB:keys:${matches[1]}`, matches[0]);
115
84
  }
116
85
  multi.del(key);
117
86
  }
118
87
  }
119
88
 
120
- multi.exec(callback);
89
+ await multi.exec();
121
90
  }
122
91
 
123
- close(callback) {
124
- this.client.quit(() => {
125
- callback();
126
- });
92
+ async close() {
93
+ await this._client.quit();
94
+ this._client = null;
127
95
  }
128
96
  };
package/package.json CHANGED
@@ -30,7 +30,7 @@
30
30
  "mysql": "2.18.1",
31
31
  "nano": "^10.0.0",
32
32
  "pg": "^8.7.3",
33
- "redis": "^3.1.2",
33
+ "redis": "^4.1.0",
34
34
  "rethinkdb": "^2.4.2",
35
35
  "simple-git": "^3.7.1"
36
36
  },
@@ -51,7 +51,7 @@
51
51
  "url": "https://github.com/ether/ueberDB.git"
52
52
  },
53
53
  "main": "./index",
54
- "version": "3.0.1",
54
+ "version": "4.0.0",
55
55
  "bugs": {
56
56
  "url": "https://github.com/ether/ueberDB/issues"
57
57
  },
package/test/test.js CHANGED
@@ -142,7 +142,6 @@ describe(__filename, function () {
142
142
 
143
143
  it('findKeys with exclusion works', async function () {
144
144
  if (database === 'mongodb') this.skip(); // TODO: Fix mongodb.
145
- if (database === 'redis') this.skip(); // TODO: Fix redis.
146
145
  const key = new Randexp(/([a-z]\w{0,20})foo\1/).gen();
147
146
  await Promise.all([
148
147
  db.set(key, true),