一:Redis的下载和安装
1:下载Redis
Redis的官方网站Download页面,Redis提示说:Redis的正式版不支持Windows,要Windows学习Redis,请点击Learn more,跳转到:https://github.com/MSOpenTech/redis
The Redis project does not officially support Windows. However,
the Microsoft Open Tech group develops and maintains this Windows port targeting Win64.
Learn more!
这里可以下载Windows版本的Redis,
我下载的是:Redis-x64-3.2.100.zip
2:安装和测试
(1):安装
将下载好的压缩包,进行解压,(强调:解压的目录不要带中文!!!)我解压到本地磁盘的:F:Redis-x64-3.2.100 下面!
如图:
(2): 测试
wins+r ,输入cmd,进入命令提示符,并进入到解压的文件夹下面:
二:Redis哨兵模式部署
参考博文:
http://blog.csdn.net/liuchuanhong1/article/details/53206028
三:Java代码批量启动windows下面的redis的服务
由于在windows 启动这么多服务太麻烦,就用java写了一个批量启动服务的代码!如下,可以直接使用!
package com.learn.redis;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* Created by dufy on 2017/3/28.
*
* cmd /c dir 是执行完dir命令后关闭命令窗口。<br/>
* cmd /k dir 是执行完dir命令后不关闭命令窗口.<br/>
* cmd /c start dir 会打开一个新窗口后执行dir指令,原窗口会关闭。<br/>
* cmd /k start dir 会打开一个新窗口后执行dir指令,原窗口不会关闭。<br/>
* redis-cli.exe -h 127.0.0.1 -p 端口<br/>
* info replication -- 查看主从复制<br/>
* info sentinel-- 查看哨兵情况<br/>
*
* window本地搭redis的哨兵模式:http://blog.csdn.net/liuchuanhong1/article/details/53206028<br/><br/>
*
* 启动服务工具类
*/
public class StartRedisServer {
private final static String redisRootPath = "F:\Redis-x64-3.2.100";
public static void main(String[] args) {
List<String> cmds = new ArrayList<String>();
String cmdRedis6379 = "cmd /k start redis-server.exe redis.conf ";//redis-server.exe redis.conf
String cmdRedis6380 = "cmd /k start redis-server.exe redis6380.conf ";//redis-server.exe redis.conf
String cmdRedis6381 = "cmd /k start redis-server.exe redis6381.conf ";//redis-server.exe redis.conf
cmds.add(cmdRedis6379);
cmds.add(cmdRedis6380);
cmds.add(cmdRedis6381);
String cmdRedis26379 = "cmd /k start redis-server.exe sentinel.conf --sentinel";//redis-server.exe sentinel26479.conf --sentinel
String cmdRedis26479 = "cmd /k start redis-server.exe sentinel26479.conf --sentinel";//redis-server.exe sentinel26479.conf --sentinel
String cmdRedis26579 = "cmd /k start redis-server.exe sentinel26579.conf --sentinel";//redis-server.exe sentinel26479.conf --sentinel
cmds.add(cmdRedis26379);
cmds.add(cmdRedis26479);
cmds.add(cmdRedis26579);
initRedisServer(cmds);
}
public static void initRedisServer(List<String> cmdStr){
if(cmdStr != null && cmdStr.size() > 0){
for (String cmd:cmdStr
) {
try {
Process exec = Runtime.getRuntime().exec(cmd, null, new File(redisRootPath));
Thread.sleep(1*1000);
}catch (InterruptedException e) {
System.out.println("线程中断异常" + e.getMessage());
e.printStackTrace();
} catch (IOException e) {
System.out.println("cmd command error" + e.getMessage());
e.printStackTrace();
}
}
}
}
}
欢迎访问我的csdn博客,我们一同成长!
"不管做什么,只要坚持下去就会看到不一样!在路上,不卑不亢!"