The following code works on redis version 3.1.2, but when I upgrade the redis libary to 4.1.0, the call back stops working. There is a REDIS server running on localhost with no password. I am using node 16 LTS.
'use strict'
import {createClient} from 'redis';
const redisClient = createClient();
redisClient.on('connect', function() {
console.log('you are now connected');
});
redisClient.on('ready', function() {
console.log('you are now ready');
});
redisClient.on('error', function(err) {
console.log(`redis error: ${err}`)
});
// added for 4.1.0 because there is no autoconnect.
await redisClient.connect();
await redisClient.set("test","value", function(err, reply) {
console.log('set complete');
});
When I run this on Redis client 3.1.2, I get "set complete" after set is call. On Redis client 4.1.0, I get nothing as if the callback isn't called. The value is set in the REDIS database even if the callback doesn't trigger. I verified the value using redis cli. There are no error messages. I do get the connect and ready event message.
What am I missing here? I am pretty sure it's something simple that I am overlooking.
Node Redis 4.x, following semver conventions, introduced many breaking changes. One of them is that it uses promises instead of callbacks. You can read all the details at https://github.com/redis/node-redis .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.