INCR命令增加“字符串”值

时间:2018-08-14 09:26:56

标签: node.js redis

我正在学习redis的INCR命令,例如:

127.0.0.1:6379> set counter 100
OK
127.0.0.1:6379> incr counter
(integer) 101

整数可以增加,

参考字符串值

127.0.0.1:6379> incr article:100001:headline 
(error) ERR value is not an integer or out of range
127.0.0.1:6379> incr "article:100001:headline"
(error) ERR value is not an integer or out of range

命令“ incr”无效

但是,字符串值可以增加为

var redis = require("redis"); 
var client = redis.createClient();

function upVote(id) {
    var key = "article:" + id  + ":votes";
    client.incr(key);
}

调用upVote(100001)时,“ article:100001:headline”增加1。

这怎么可能?

0 个答案:

没有答案