nodejs使用radis

来源:互联网 发布:mysql dump 导出表 编辑:程序博客网 时间:2024/06/07 23:16

npm install redis 安装nodejs redis 客户端

sudo apt-get install redis-server 安装redis-server

redis-server 这一步运行redis-server

代码:

var redis = require("redis"),    client = redis.createClient(); // if you'd like to select database 3, instead of 0 (default), call // client.select(3, function() { /* ... */ });  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.hkeys("hash key", function (err, replies) {    console.log(replies.length + " replies:");    replies.forEach(function (reply, i) {        console.log("    " + i + ": " + reply);    });    client.quit();});
默认port 6379

0 0
原创粉丝点击