bonsaif 1.10.29 → 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.
@@ -277,6 +277,37 @@ const scard=async( options, db, key )=>{ // SCARD key
277
277
  })
278
278
  }
279
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
+
280
311
  const hset=async( options,db, key, values )=>{ // HSET key field value [ field value ...]
281
312
  const exec = require("./exec");
282
313
  const redisConn = await exec.redisConn(options);
@@ -308,7 +339,7 @@ const hset=async( options,db, key, values )=>{ // HSET key field value [ field
308
339
  })
309
340
  }
310
341
 
311
- const hgetall=async(options, db, key )=>{ // SMEMBERS key
342
+ const hgetall=async(options, db, key )=>{ // HGETALL key
312
343
  const exec = require("./exec");
313
344
  const redisConn = await exec.redisConn(options);
314
345
  const start = Date.now();
@@ -331,6 +362,44 @@ const hgetall=async(options, db, key )=>{ // SMEMBERS key
331
362
  })
332
363
  }
333
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
+
334
403
  const del=async( options,db, key )=>{ //DEL key [key ...]
335
404
  const exec = require("./exec");
336
405
  const redisConn = await exec.redisConn(options);
@@ -570,7 +639,7 @@ const hmset=async( options,db, key, values )=>{ // HSET key field value [ field
570
639
  }
571
640
 
572
641
 
573
- const expire_=async( options,db, key, expire )=>{ // HSET key field value [ field value ...]
642
+ const expire=async( options,db, key, expire )=>{ // EXPIRE key seconds
574
643
  const exec = require("./exec");
575
644
  const redisConn = await exec.redisConn(options);
576
645
  const start = Date.now();
@@ -579,7 +648,6 @@ const expire_=async( options,db, key, expire )=>{ // HSET key field value [ fie
579
648
  return new Promise((resolve, reject)=>{
580
649
  try{
581
650
  redisConn.select(db,function() { /* ... */ }); //base 1
582
- // hset con multiples campos esta depreciado en versiones mayores a node 6
583
651
  redisConn.expire(key, expire, function (err, res) {
584
652
  const end = Date.now();
585
653
  const time = end - start;
@@ -662,7 +730,7 @@ const api=async(options, dbm, json)=>{
662
730
  let lstop = json.stop!=null?json.stop*1:-1;
663
731
  let {field:id, val:vid} = getFirstField(filter);
664
732
 
665
- 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'];
666
734
  for (let x of ltdml){
667
735
  if (utl.ObjectEmpty(json,x)){
668
736
  dml = x; break;
@@ -684,13 +752,14 @@ const api=async(options, dbm, json)=>{
684
752
  case 'smembers': r = await smembers(options,dbm,key,toJson); break;
685
753
  case 'hset': r = await hset(options,dbm,key,value,expire); break;
686
754
  case 'hgetall': r = await hgetall(options,dbm,key); break;
755
+ case 'hmget': r = await hmget(options,dbm,key,value); break;
687
756
  case 'del': r = await del(options,dbm,key); break;
688
757
  case 'incrbyfloat': r = await incrbyfloat(options,dbm,key,value,expire,counter); break;
689
758
  case 'expireat': r = await expireat(options,dbm,key,expire); break;
690
759
  case 'setnx': r = await setnx(options,dbm,key,value,expire); break;
691
760
  case 'hsetnx': r = await hsetnx(options,dbm,key,value,expire); break;
692
761
  case 'hmset': r = await hmset(options,dbm,key,value,expire); break;
693
- //case 'expire': r = await expire_(options,dbm,key,expire); break;
762
+ case 'expire': r = await expire(options,dbm,key,expire); break;
694
763
  case 'lrange': r = await lrange(options,dbm,key,lstart,lstop); break;
695
764
  case 'keys': r = await keys(options,dbm,key); break;
696
765
  default: r = {"dml":"404", "err":"dml not found."};
@@ -789,13 +858,16 @@ module.exports ={
789
858
  srem,
790
859
  smembers,
791
860
  scard,
861
+ sunionstore,
792
862
  hset,
793
863
  hgetall,
864
+ hmget,
794
865
  del,
795
866
  hfind,
796
867
  upsert,
797
868
  api,
798
869
  incrbyfloat,
870
+ expire,
799
871
  expireat,
800
872
  lrange,
801
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.29",
17
+ "version": "1.10.30",
18
18
  "main": "index.js",
19
19
  "directories": {
20
20
  "lib": "lib"