Node js redis

const redis = require('redis');//redis
const client = redis.createClient(8888, '172.16.4.2');
  //redis操作
  client.set("hello", "{\"a\":\"1\", \"b\":\"2\"}") 
  client.get("hello", function(err, value){
       console.log(value);
  
       jsonObj = JSON.parse(value);//将字符串转换为json对象
       console.log(jsonObj.a);
  
   })
   client.expire('hello', 3);

   // NX是不存在时才set, XX是存在时才set, EX是秒,PX是毫秒
   client.set("hello", "{\"a\":\"1\", \"b\":\"2\"}", "NX", "EX", 60*10);

队列

client.rpush('hello11Lists','1');

 

posted @ 2019-03-05 11:43  glory.xu  阅读(139)  评论(0编辑  收藏  举报