1.redis 安装(前题是需要一个redis服务器):
通过:D:\nodeJs\redis-2.4.5-win32-win64\64bit>redis-server.exe启动redis服务。
2.redis服务启动后可以通过redis的客户端来进行key,value的set和get.
D:\nodeJs\redis-2.4.5-win32-win64\64bit>redis-cli.exe,
其中常用的redis命令可参考:
http://doc.redisfans.com/key/keys.html
3.node与redis交互,npm install redis.
简单代码示例:
var redis = require("redis");
var client = redis.createClient();
client.on("error", function (err) {
console.log("Error " + err);
});
client.set("string key", "string val", redis.print);
client.hset("hash key", "hashtest 1", "some value", redis.print);
client.hset(["hash key", "hashtest 2", "some other value"], redis.print);
client.get("string key", function(err,replies){
console.log(replies);
})
client.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
client.quit();
});