I'm trying to use zadd function in redis its throws like an error.
zadd function not found in redis.
import { createClient } from 'redis';
const client = createClient({
host: 'localhost',
port: 32768,
});
client.connect().then(() => {
console.log('connected');
}).catch((err) => {
console.log('error', err);
});
client.set('foo', 'no');
client.get('foo', (err, result) => {
console.log(result);
}).then((result) => {
console.log(result);
});
client.zadd('myzset', 1, 'one'); // client.zadd is not a function
CodePudding user response:
Node Redis 4.x introduced several breaking changes including support for Promises. All of the commands were also changed to be either camel-cased or uppercased.
Try this:
client.zAdd('myzset', 1, 'one');
Or this:
client.ZADD('myzset', 1, 'one');
You can find the information about this near the top of the README for Node Redis.
CodePudding user response:
This works for me,
client.zAdd('key', [{
score: 1,
value: 'a'
}, {
score: 2,
value: 'b'
}])