Asynchronous operations are cumbersome. Difficult to control. The following is a synchronized library Bluebird. The usage is simple. Look at you and you'll know.
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}: "";varClient =redis.createclient (Rds_port, Rds_host, rds_opts);
Async Test () {
Let res = await client.keysasync ("*");
Console.log (RES);
}client.on (' Connect ',function() {Console.log (' Successful connection '); //---------------Core Usage----------------------------------- //------------------Client[cmd] (param, CB)-----------------Test ();})//You can also use this method to enter a password//Client.auth (rds_pwd, function () {//Console.log ("Verified by");// })//This event is triggered when the connection to the Redis server is successful, indicating that the command is ready to be received and that the client command will be present in the queue before the event is triggered, and then called sequentially when everything is ready .Client.on (' Ready ',function() {Console.log (' Ready ');}) Client.on (' Error ',function(Err) {Console.log (' ErrorEvent-' + client.host + ': ' + client.port + '-' +err);})
Redis synchronization operation