:::: MENU ::::

Share is Care

  • Make your business grow up be paster

  • One stop solution for your business need

  • Tell Us, What do you want ?

Kamis, 16 Juni 2022




Kali ini kita akan belajar penggunaan function hmset pada redis untuk menyimpan data. Untuk mengimplementasikannya saya menggunakan bahasa nodejs.

Berikut adalah contoh-contoh penggunaan function hmset pada redis.


update(cb) {
  const id = this.id;
  db.set(`user:id:${this.name}`, id, (err) => {
   if (err) return cb(err);
   db.hmset(`user:${id}`, this, (err) => {
    cb(err);
   });
  });
 }
 

Jika datanya object, maka seperti ini contohnya


db.set('user:id:' + user.name, id, function(err) {
  if (err) return fn(err);
  db.hmset('user:' + id, user, function(err) {
   fn(err);
  });
 });
 

Jika datanya array, maka seperti ini contohnya

app.post('/call/add', function(req,res){
 var newCall = {
  name: req.body.name,
  company: req.body.company,
  phone: req.body.phone,
  time: req.body.time
 };

 client.hmset('call', [
  'name', newCall.name,
  'company', newCall.company,
  'phone', newCall.phone,
  'time', newCall.time,
 ], function(error, reply){
  if(error){
   console.log(error);
  }
  console.log(reply);
  return res.redirect('/');
 });
});

Jika datanya json, maka seperti ini contohnya

client.hmset('jsApiTicket', json, function (err, response) {

Refference Tabnine

0 komentar:

Posting Komentar

A call-to-action text Contact us