linux安装及配置之前写过了http://www.cnblogs.com/zycbloger/p/6226682.html
windows安装
下载地址:https://github.com/MicrosoftArchive/redis/releases
我下的是zip,解压后
具体的配置和linux一样看那个就行了!
打开一个 cmd 窗口 使用cd命令切换目录到 解压的目录运行
redis-server.exe redis.windows.conf
如果想方便的话,可以把 redis 的路径加到系统的环境变量里或者写个 .bat文件 redis-server redis.windows.conf 双击就可以运行了,这样就省得再输路径了,后面的那个 redis.windows.conf 可以省略,如果省略,会启用默认的。输入之后,会显示如下界面:
另启一个cmd窗口,原来的不要关闭
切换到redis目录下运行
redis-cli.exe -h 127.0.0.1 -p 6000 -a xxx
ping 如果 pong 就说明是连接通过了
安装 redis 依赖包
npm install redis --save
var redis = require(‘redis‘),
config = require(‘../config‘),
dbConfig = config.redis,
RDS_PORT = dbConfig.port, //端口号
RDS_HOST = dbConfig.host, //服务器IP
RDS_PWD = dbConfig.pass, //密码
RDS_OPTS = {auth_pass: RDS_PWD},
client = redis.createClient(RDS_PORT, RDS_HOST, RDS_OPTS);
client.on(‘ready‘,function(res){
console.log(‘ready‘);
});
client.on(‘end‘,function(err){
console.log(‘end‘);
});
client.on(‘error‘, function (err) {
console.log(err);
});
client.on(‘connect‘,function(){
console.log(‘redis connect success!‘);
});
结合node 使用
client.set(‘name‘, ‘zyc‘, function (err, res) {
// todo..
});
client.get(‘name‘, function (err, res) {
// todo...
});
client.hmset("hosts", "mjr", "1", "another", "23", "home", "1234");
client.hgetall("hosts", function (err, obj) {
console.dir(obj);
});
client.hmset(key2, {
"0123456789": "abcdefghij", // NOTE: key and value will be coerced to strings
"some manner of key": "a type of value"
});
client.zadd(table, score, id, function (err, res) {
});
//删除单个
client.zrem(table, id, function (err, res) {
));
// 删除多个
client.zrem(table, arr, function (err, res) {
});
// 从大到小 查询
client.zrevrange(table, 0, -1, function (err, res) {
})
https://www.npmjs.com/package/redis 可以去redis看一下相关的资料。
原文:https://www.cnblogs.com/shaozhu520/p/10859276.html