【问题标题】:How to store a hash in Redis. I am using hset如何在 Redis 中存储哈希。我正在使用 hset
【发布时间】:2021-12-13 00:04:16
【问题描述】:

我想在 redis 中存储一个 Hash 对象,但它不起作用。

const UpdateStatusOfEventofMap = (eventId , status)=>{
 console.log('in function eventId --->' , eventId , 'status == > ' , status)
 return new Promise((resolve, reject) => {
   try {
     // let data = JSON.stringify(GetResponderData);
     let updateEventStatus = client.hset('StatusOfEvent',eventId ,status,(err,reply)=>{
       if(err) console.log(err)
       resolve(reply)
     })
   } catch (e) {
       return reject(e)
   }
});
}

【问题讨论】:

  • 当前代码有什么问题?你得到什么样的错误?

标签: javascript node.js redis


【解决方案1】:

使用 hmset 代替 hset。试试这个代码块。

const UpdateStatusOfEventofMap = (eventId , status)=>{
 console.log('in function eventId --->' , eventId , 'status == > ' , status)
 return new Promise((resolve, reject) => {
   try {
     // let data = JSON.stringify(GetResponderData);
     let updateEventStatus = client.hmset('StatusOfEvent',eventId ,status,(err,reply)=>{
       if(err) console.log(err)
       resolve(reply)
     })
   } catch (e) {
       return reject(e)
   }
});
}

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-26
  • 2020-06-29
相关资源
最近更新 更多