码迷,mamicode.com
首页 > 其他好文 > 详细

redis 同步化操作

时间:2018-10-11 18:53:41      阅读:105      评论:0      收藏:0      [点我收藏+]

标签:简单   sas   eve   验证   调用   存在   cmd   erro   --   

异步化操作是很麻烦的的。不好控。下面介绍个同步化的库bluebird.用法很简单.看下你还子就知道了

const redis = require(‘redis‘);

  const bluebird = require(‘bluebird‘);
  bluebird.promisifyAll(redis.RedisClient.prototype);
  bluebird.promisifyAll(redis.Multi.prototype);

let RDS_PORT = 6379;
let RDS_HOST = "127.0.0.1";
let RDS_PWD = "";
let RDS_OPTS = RDS_PWD ? {auth_pass:RDS_PWD} : "";

var client = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);

async test() {
let res = await client.keysAsync("*");
  console.log(res);
} client.on(
‘connect‘, function(){ console.log(‘连接成功‘); //--------------- 核心用法----------------------------------- //------------------ client[cmd](param, cb)----------------- test(); }) // 也可通过此方法来输入密码 // client.auth(RDS_PWD, function(){ // console.log("通过验证"); // }) // 当与redis服务器连接成功后会触发这个事件,此时表示已经准备好接收命令,当这个事件触发之前client命令会存在队列中,当一切准备就绪后按顺序调用 client.on(‘ready‘, function(){ console.log(‘ready‘); }) client.on(‘error‘, function (err) { console.log(‘errorevent - ‘ + client.host + ‘:‘ + client.port + ‘ - ‘ + err); })

 

redis 同步化操作

标签:简单   sas   eve   验证   调用   存在   cmd   erro   --   

原文地址:https://www.cnblogs.com/honghong87/p/9773506.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!