bonsaif 1.10.16 → 1.10.18

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.
@@ -475,6 +475,68 @@ const setnx=async(options, db, key, value, expire )=>{
475
475
  })
476
476
  }
477
477
 
478
+ const hsetnx=async( options,db, key, values )=>{ // HSET key field value [ field value ...]
479
+ const exec = require("./exec");
480
+ const redisConn = await exec.redisConn(options);
481
+ const start = Date.now();
482
+ let Fields = new Array();
483
+ //Siempre el value debe estar en json
484
+ for (const [key, value] of Object.entries(values)) {
485
+ Fields.push(key);
486
+ Fields.push(value);
487
+ }
488
+
489
+ return new Promise((resolve, reject)=>{
490
+ try{
491
+ redisConn.select(db,function() { /* ... */ }); //base 1
492
+ // hset con multiples campos esta depreciado en versiones mayores a node 6
493
+ redisConn.hsetnx(key, Fields, function (err, res) {
494
+ const end = Date.now();
495
+ const time = end - start;
496
+ resolve({"hsetnx":key, "err":err, "res":res, "value":values, "time":utl.milisegundosASegundos(time)});
497
+ try{
498
+ exec.redisClose(redisConn);
499
+ }catch(e){
500
+ utl.log('err.hsetnx '+e);
501
+ }
502
+ });
503
+ }catch(e){
504
+ utl.log('err hsetnx'+e);
505
+ }
506
+ })
507
+ }
508
+
509
+ const hmset=async( options,db, key, values )=>{ // HSET key field value [ field value ...]
510
+ const exec = require("./exec");
511
+ const redisConn = await exec.redisConn(options);
512
+ const start = Date.now();
513
+ let Fields = new Array();
514
+ //Siempre el value debe estar en json
515
+ for (const [key, value] of Object.entries(values)) {
516
+ Fields.push(key);
517
+ Fields.push(value);
518
+ }
519
+
520
+ return new Promise((resolve, reject)=>{
521
+ try{
522
+ redisConn.select(db,function() { /* ... */ }); //base 1
523
+ // hset con multiples campos esta depreciado en versiones mayores a node 6
524
+ redisConn.hmset(key, Fields, function (err, res) {
525
+ const end = Date.now();
526
+ const time = end - start;
527
+ resolve({"hmset":key, "err":err, "res":res, "value":values, "time":utl.milisegundosASegundos(time)});
528
+ try{
529
+ exec.redisClose(redisConn);
530
+ }catch(e){
531
+ utl.log('err.hmset '+e);
532
+ }
533
+ });
534
+ }catch(e){
535
+ utl.log('err hmset'+e);
536
+ }
537
+ })
538
+ }
539
+
478
540
  const api=async(options, dbm, json)=>{
479
541
  const exec = require("./exec");
480
542
 
@@ -516,6 +578,8 @@ const api=async(options, dbm, json)=>{
516
578
  case 'incrbyfloat': r = await incrbyfloat(options,dbm,key,value,expire,counter); break;
517
579
  case 'expireat': r = await expireat(options,dbm,key,expire); break;
518
580
  case 'setnx': r = await setnx(options,dbm,key,value,expire); break;
581
+ case 'hsetnx': r = await hsetnx(options,dbm,key,value,expire); break;
582
+ case 'hmset': r = await hmset(options,dbm,key,value,expire); break;
519
583
  default: r = {"dml":"404", "err":"dml not found."};
520
584
  }
521
585
 
package/lib/utl.js CHANGED
@@ -249,8 +249,10 @@ const random=(o)=>{
249
249
  };
250
250
 
251
251
  const valueIn=(o)=>{
252
- let vin = o.in != null ? o.in.split(',') : '';
253
- let v = o.value != null ? o.value.split(',') : '';
252
+ let {value='', in:in_=''} = o ? o : {};
253
+ value = ''+value; in_ = ''+in_;
254
+ let vin = in_ != null ? in_.split(',') : '';
255
+ let v = value != null ? value.split(',') : '';
254
256
 
255
257
  for (let xv of v){
256
258
  for (let xvin of vin ){
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.16",
17
+ "version": "1.10.18",
18
18
  "main": "index.js",
19
19
  "directories": {
20
20
  "lib": "lib"