bonsaif 1.10.28 → 1.10.30

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.
Files changed (2) hide show
  1. package/lib/hookup/redis.js +103 -5
  2. package/package.json +1 -1
@@ -252,6 +252,62 @@ const smembers=async( options, db, key, toJson )=>{ // SMEMBERS key
252
252
  })
253
253
  }
254
254
 
255
+ const scard=async( options, db, key )=>{ // SCARD key
256
+ const exec = require("./exec");
257
+ const redisConn = await exec.redisConn(options);
258
+ const start = Date.now();
259
+ return new Promise((resolve, reject)=>{
260
+ try{
261
+ redisConn.select(db,function() { /* ... */ }); //base 1
262
+ redisConn.scard(key, function (err, res) {
263
+
264
+ const end = Date.now();
265
+ const time = end - start;
266
+
267
+ resolve({"scard":key, "err":err, "res":res, "time":utl.milisegundosASegundos(time)});
268
+ try{
269
+ exec.redisClose(redisConn);
270
+ }catch(e){
271
+ utl.log('err.scard '+e);
272
+ }
273
+ });
274
+ }catch(e){
275
+ utl.log('err scard'+e);
276
+ }
277
+ })
278
+ }
279
+
280
+ const sunionstore=async( options, db, destination, keys )=>{ // SUNIONSTORE destination key [key ...]
281
+ const exec = require("./exec");
282
+ const redisConn = await exec.redisConn(options);
283
+ const start = Date.now();
284
+
285
+ // Asegurarse de que keys sea un array
286
+ if (!Array.isArray(keys)) {
287
+ keys = [keys];
288
+ }
289
+
290
+ return new Promise((resolve, reject)=>{
291
+ try{
292
+ redisConn.select(db,function() { /* ... */ }); //base 1
293
+ redisConn.sunionstore([destination, ...keys], function (err, res) {
294
+
295
+ const end = Date.now();
296
+ const time = end - start;
297
+
298
+ resolve({"sunionstore":destination, "keys":keys, "err":err, "res":res, "time":utl.milisegundosASegundos(time)});
299
+ try{
300
+ exec.redisClose(redisConn);
301
+ }catch(e){
302
+ utl.log('err.sunionstore '+e);
303
+ }
304
+ });
305
+ }catch(e){
306
+ utl.log('err sunionstore'+e);
307
+ }
308
+ })
309
+ }
310
+
255
311
  const hset=async( options,db, key, values )=>{ // HSET key field value [ field value ...]
256
312
  const exec = require("./exec");
257
313
  const redisConn = await exec.redisConn(options);
@@ -283,7 +339,7 @@ const hset=async( options,db, key, values )=>{ // HSET key field value [ field
283
339
  })
284
340
  }
285
341
 
286
- const hgetall=async(options, db, key )=>{ // SMEMBERS key
342
+ const hgetall=async(options, db, key )=>{ // HGETALL key
287
343
  const exec = require("./exec");
288
344
  const redisConn = await exec.redisConn(options);
289
345
  const start = Date.now();
@@ -306,6 +362,44 @@ const hgetall=async(options, db, key )=>{ // SMEMBERS key
306
362
  })
307
363
  }
308
364
 
365
+ const hmget=async(options, db, key, fields )=>{ // HMGET key field [field ...]
366
+ const exec = require("./exec");
367
+ const redisConn = await exec.redisConn(options);
368
+ const start = Date.now();
369
+
370
+ // Asegurarse de que fields sea un array
371
+ if (!Array.isArray(fields)) {
372
+ fields = [fields];
373
+ }
374
+
375
+ return new Promise((resolve, reject)=>{
376
+ try{
377
+ redisConn.select(db,function() { /* ... */ }); //base 1
378
+ redisConn.hmget(key, fields, function (err, res) {
379
+ const end = Date.now();
380
+ const time = end - start;
381
+
382
+ // Crear un objeto con los campos y valores
383
+ let result = {};
384
+ if (res) {
385
+ fields.forEach((field, index) => {
386
+ result[field] = res[index];
387
+ });
388
+ }
389
+
390
+ resolve({"hmget":key, "fields":fields, "err":err, "res":result, "time":utl.milisegundosASegundos(time)});
391
+ try{
392
+ exec.redisClose(redisConn);
393
+ }catch(e){
394
+ utl.log('err.hmget '+e);
395
+ }
396
+ });
397
+ }catch(e){
398
+ utl.log('err hmget'+e);
399
+ }
400
+ })
401
+ }
402
+
309
403
  const del=async( options,db, key )=>{ //DEL key [key ...]
310
404
  const exec = require("./exec");
311
405
  const redisConn = await exec.redisConn(options);
@@ -545,7 +639,7 @@ const hmset=async( options,db, key, values )=>{ // HSET key field value [ field
545
639
  }
546
640
 
547
641
 
548
- const expire_=async( options,db, key, expire )=>{ // HSET key field value [ field value ...]
642
+ const expire=async( options,db, key, expire )=>{ // EXPIRE key seconds
549
643
  const exec = require("./exec");
550
644
  const redisConn = await exec.redisConn(options);
551
645
  const start = Date.now();
@@ -554,7 +648,6 @@ const expire_=async( options,db, key, expire )=>{ // HSET key field value [ fie
554
648
  return new Promise((resolve, reject)=>{
555
649
  try{
556
650
  redisConn.select(db,function() { /* ... */ }); //base 1
557
- // hset con multiples campos esta depreciado en versiones mayores a node 6
558
651
  redisConn.expire(key, expire, function (err, res) {
559
652
  const end = Date.now();
560
653
  const time = end - start;
@@ -637,7 +730,7 @@ const api=async(options, dbm, json)=>{
637
730
  let lstop = json.stop!=null?json.stop*1:-1;
638
731
  let {field:id, val:vid} = getFirstField(filter);
639
732
 
640
- let ltdml = ['hfind','upsert','set','get','scan','incrby','sadd','srem','smembers','hset','hgetall','del','incrbyfloat','expireat','setnx','hsetnx','hmset','expire','lrange','keys'];
733
+ let ltdml = ['hfind','upsert','set','get','scan','incrby','sadd','srem','smembers','hset','hgetall','hmget','del','incrbyfloat','expireat','setnx','hsetnx','hmset','expire','lrange','keys'];
641
734
  for (let x of ltdml){
642
735
  if (utl.ObjectEmpty(json,x)){
643
736
  dml = x; break;
@@ -659,13 +752,14 @@ const api=async(options, dbm, json)=>{
659
752
  case 'smembers': r = await smembers(options,dbm,key,toJson); break;
660
753
  case 'hset': r = await hset(options,dbm,key,value,expire); break;
661
754
  case 'hgetall': r = await hgetall(options,dbm,key); break;
755
+ case 'hmget': r = await hmget(options,dbm,key,value); break;
662
756
  case 'del': r = await del(options,dbm,key); break;
663
757
  case 'incrbyfloat': r = await incrbyfloat(options,dbm,key,value,expire,counter); break;
664
758
  case 'expireat': r = await expireat(options,dbm,key,expire); break;
665
759
  case 'setnx': r = await setnx(options,dbm,key,value,expire); break;
666
760
  case 'hsetnx': r = await hsetnx(options,dbm,key,value,expire); break;
667
761
  case 'hmset': r = await hmset(options,dbm,key,value,expire); break;
668
- //case 'expire': r = await expire_(options,dbm,key,expire); break;
762
+ case 'expire': r = await expire(options,dbm,key,expire); break;
669
763
  case 'lrange': r = await lrange(options,dbm,key,lstart,lstop); break;
670
764
  case 'keys': r = await keys(options,dbm,key); break;
671
765
  default: r = {"dml":"404", "err":"dml not found."};
@@ -763,13 +857,17 @@ module.exports ={
763
857
  sadd,
764
858
  srem,
765
859
  smembers,
860
+ scard,
861
+ sunionstore,
766
862
  hset,
767
863
  hgetall,
864
+ hmget,
768
865
  del,
769
866
  hfind,
770
867
  upsert,
771
868
  api,
772
869
  incrbyfloat,
870
+ expire,
773
871
  expireat,
774
872
  lrange,
775
873
  keys
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "name": "bonsaif",
16
16
  "description": "bonsaif is a library to connect to bonsaif apis",
17
- "version": "1.10.28",
17
+ "version": "1.10.30",
18
18
  "main": "index.js",
19
19
  "directories": {
20
20
  "lib": "lib"