bonsaif 1.10.31 → 1.10.32
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/lib/hookup/redis.js +47 -20
- package/package.json +1 -1
package/lib/hookup/redis.js
CHANGED
|
@@ -9,31 +9,55 @@
|
|
|
9
9
|
let tag = ` ::: B[]NSAIF() ::: => redis.js `;
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
const scan=async(options,db,
|
|
12
|
+
const scan=async(options,db, cursor, pattern, count)=>{ // SCAN cursor [MATCH pattern] [COUNT count]
|
|
13
13
|
const exec = require("./exec");
|
|
14
14
|
const redisConn = await exec.redisConn(options);
|
|
15
15
|
const start = Date.now();
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
cursor = cursor!=null ? cursor : '0';
|
|
18
|
+
pattern = pattern!=null ? pattern : '*';
|
|
19
|
+
count = count!=null ? count : 100;
|
|
20
|
+
|
|
21
|
+
return new Promise((resolve, reject)=>{
|
|
22
|
+
try{
|
|
23
|
+
redisConn.select(db,function() { /* ... */ });
|
|
24
|
+
|
|
25
|
+
let args = [cursor];
|
|
26
|
+
if (pattern) {
|
|
27
|
+
args.push('MATCH', pattern);
|
|
28
|
+
}
|
|
29
|
+
if (count) {
|
|
30
|
+
args.push('COUNT', count);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
redisConn.scan(args, function (err, res) {
|
|
34
|
+
if (err) {
|
|
35
|
+
reject(err);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const end = Date.now();
|
|
40
|
+
const time = end - start;
|
|
41
|
+
|
|
42
|
+
// res[0] es el nuevo cursor, res[1] es el array de keys
|
|
43
|
+
resolve({
|
|
44
|
+
"cursor": res[0],
|
|
45
|
+
"keys": res[1],
|
|
46
|
+
"count": res[1].length,
|
|
47
|
+
"time": utl.milisegundosASegundos(time)
|
|
48
|
+
});
|
|
49
|
+
|
|
17
50
|
try{
|
|
18
|
-
|
|
19
|
-
const redisScan = require('node-redis-scan');
|
|
20
|
-
const scanner = new redisScan(redisConn);
|
|
21
|
-
scanner.scan(key, (err, matchingKeys) => {
|
|
22
|
-
if (err) throw(err);
|
|
23
|
-
const end = Date.now();
|
|
24
|
-
const time = end - start;
|
|
25
|
-
resolve({"count":matchingKeys.length, "keys":matchingKeys, "time":utl.milisegundosASegundos(time)});
|
|
26
|
-
|
|
27
|
-
try{
|
|
28
|
-
exec.redisClose(redisConn);
|
|
29
|
-
}catch(e){
|
|
30
|
-
utl.log('err.scan '+e);
|
|
31
|
-
}
|
|
32
|
-
});
|
|
51
|
+
exec.redisClose(redisConn);
|
|
33
52
|
}catch(e){
|
|
34
|
-
utl.log('err
|
|
53
|
+
utl.log('err.scan '+e);
|
|
35
54
|
}
|
|
36
|
-
})
|
|
55
|
+
});
|
|
56
|
+
}catch(e){
|
|
57
|
+
utl.log('err scan: '+e);
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
60
|
+
})
|
|
37
61
|
}
|
|
38
62
|
|
|
39
63
|
const set=async(options, db, key, value, expire )=>{
|
|
@@ -772,6 +796,9 @@ const api=async(options, dbm, json)=>{
|
|
|
772
796
|
let keysArray = json.keys!=null ? json.keys : [];
|
|
773
797
|
let fieldsArray = json.fields!=null ? json.fields : [];
|
|
774
798
|
let destination = json.destination!=null ? json.destination : '';
|
|
799
|
+
let cursor = json.cursor!=null ? json.cursor : '0';
|
|
800
|
+
let pattern = json.pattern!=null ? json.pattern : key;
|
|
801
|
+
let scan_count = json.count!=null ? json.count : 100;
|
|
775
802
|
|
|
776
803
|
let r;
|
|
777
804
|
switch (dml){
|
|
@@ -779,7 +806,7 @@ const api=async(options, dbm, json)=>{
|
|
|
779
806
|
case 'get': r = await get(options,dbm,key); break;
|
|
780
807
|
case 'hfind': r = await hfind(options,dbm,key,filter,order,limit); break;
|
|
781
808
|
case 'upsert': r = await upsert(options,dbm,key,value,id,vid,expire); break;
|
|
782
|
-
case 'scan': r = await scan(options,dbm,
|
|
809
|
+
case 'scan': r = await scan(options,dbm,cursor,pattern,scan_count); break;
|
|
783
810
|
case 'incrby': r = await incrby(options,dbm,key,value,expire,counter); break;
|
|
784
811
|
case 'sadd': r = await sadd(options,dbm,key,value,expire); break;
|
|
785
812
|
case 'srem': r = await srem(options,dbm,key,value); break;
|