我尝试在node_redis中创建队列。而且我不知道如何创建队列。我尝试使用zadd方法。我从REDIS运行了示例代码,下一个代码却出错:
var redis = require("redis");
client = redis.createClient();
const {promisify} = require('util');
const getAsync = promisify(client.get).bind(client);
client.on("error", function (err) {
console.log("Error " + err);
});
var args = [ 'myzset', 1, 'one', 2, 'two', 3, 'three', 99, 'ninety-nine' ];
client.zadd(args, function (err, response) {
if (err) throw err;
console.log('added '+response+' items.');
// -Infinity and +Infinity also work
var args1 = [ 'myzset', '+inf', '-inf' ];
client.zrevrangebyscore(args1, function (err, response) {
if (err) throw err;
console.log('example1', response);
// write your code here
});
var max = 3, min = 1, offset = 1, count = 2;
var args2 = [ 'myzset', max, min, 'WITHSCORES', 'LIMIT', offset, count ];
client.zrevrangebyscore(args2, function (err, response) {
if (err) throw err;
console.log('example2', response);
// write your code here
});
});
client.quit();
一个错误:
对于诸如client.set或client.get的简单方法,我没有出错。 如何对node_redis使用其他方法? 我已经在Windows操作系统上安装了Redis。
答案 0 :(得分:0)
我在question上找到了答案;
我应该打电话给client.quit();在下一种方法中:
var args = [ 'myzset', 1, 'one', 2, 'two', 3, 'three', 99, 'ninety-nine' ];
client.zadd(args, function (err, response) {
if (err) throw err;
console.log('added '+response+' items.');
// -Infinity and +Infinity also work
var args1 = [ 'myzset', '+inf', '-inf' ];
client.zrevrangebyscore(args1, function (err, response) {
if (err) throw err;
console.log('example1', response);
// write your code here
});
var max = 3, min = 1, offset = 1, count = 2;
var args2 = [ 'myzset', max, min, 'WITHSCORES', 'LIMIT', offset, count ];
client.zrevrangebyscore(args2, function (err, response) {
if (err) throw err;
console.log('example2', response);
// write your code here
});
client.quit();
});
client.quit();必须在zadd方法内部。