我正在尝试在 Node.js 中使用 Redis。我做错了什么......我无法理解它。
var redis = require("redis"), client = redis.createClient();
client.on("error", function (err) {
console.log("error event - " + client.host + ":" + client.port + " - " + err);
});
/* first attempt */
console.log('first attempt');
var before = client.get("test");
console.log(before);
if(client.exists("test")) {
console.log("The value exists");
} else {
console.log("The value doesn't exists");
client.set("test","koen");
}
var after = client.get("test");
console.log(after);
/* second attempt */
console.log('--------------');
console.log('second attempt');
var before = client.get("test");
console.log(before);
if(client.exists("test")) {
console.log("The value exists");
} else {
console.log("The value doesn't exists");
client.set("test","koen");
}
var after = client.get("test");
console.log(after);
我无法设置任何键...控制台中显示以下内容:
first attempt
false
The value doesn't exists
false
--------------
second attempt
false
The value doesn't exists
false