1、下载Windows 版本 Redis:

https://github.com/ServiceStack/redis-windows

2、 解压文件:

F:\开源代码学习\01_Redis 打开 目录:F:\开源代码学习\01_Redis\src\msopentech\redis64-2.6.12.1

3、启动Redis

指向CMD命令:

4、测试安装成果:

新建一个CMD 窗口:

运行命令:

5、讲Redis 加工成 windows :

namespace RedisService
{
/// <summary>
/// 参考文档:
/// http://www.saltwebsites.com/2012/how-run-redis-service-under-windows
///
/// sc create Redis start= auto DisplayName= Redis binpath= "\"C:\Program Files\Redis\RedisService.exe\" \"C:\Program Files\Redis\redis.conf\""
///
/// </summary>
class Program : ServiceBase
{
const string RedisServer = "redis-server.exe";
const string RedisCLI = "redis-cli.exe";
static string _path; static int _port; static void Main(string[] args)
{
_path = AppDomain.CurrentDomain.BaseDirectory;
if (!File.Exists(Path.Combine(_path, RedisServer)))
Exit("Couldn`t find " + RedisServer); if (!File.Exists(Path.Combine(_path, RedisCLI)))
Exit("Couldn`t find " + RedisCLI); if (Environment.UserInteractive)
{
SetConsoleCtrlHandler(ConsoleCtrlCheck, true);
//Console.CancelKeyPress += (sender, eventArgs) => StopRedis();
StartRedis(args.Length == ? args[] : null);
}
else
Run(new Program());
} protected override void OnStart(string[] args)
{
var arguments = Environment.GetCommandLineArgs();
if (arguments.Length > )
Exit("Too many arguments");
base.OnStart(args);
StartRedis(arguments.Length == ? arguments[] : null);
} protected override void OnStop()
{
base.OnStop();
StopRedis();
} static void StartRedis(string configPath = null)
{
var pi = new ProcessStartInfo(Path.Combine(_path, RedisServer)); if (configPath != null)
{
FindPort(configPath); // Workaround for spaces in configuration filename.
pi.Arguments = Path.GetFileName(configPath);
pi.WorkingDirectory = Path.GetDirectoryName(configPath);
} using (var process = new Process { StartInfo = pi })
{
if (process.Start())
if (Environment.UserInteractive)
process.WaitForExit();
else
{
}
else
Exit("Failed to start Redis process");
}
} private static void FindPort(string path)
{
using (var reader = new StreamReader(path))
{
string line;
while ((line = reader.ReadLine()) != null)
{
if (line.IndexOf("port") == )
{
_port = int.Parse(line.Substring(, line.Length - ));
break;
}
}
if (_port == )
Exit("Couldn`t find Redis port in config file");
}
} static void StopRedis()
{
var pi = new ProcessStartInfo(Path.Combine(_path, RedisCLI)) { Arguments = (_port == ? "" : String.Format("-p {0} ", _port)) + "shutdown" }; if (!(new Process { StartInfo = pi }).Start())
Exit("Failed to stop Redis process");
} static void Exit(string message)
{
if (Environment.UserInteractive)
{
Console.WriteLine(message);
Environment.Exit(-);
}
else
{
//File.WriteAllText(Path.Combine(_path, "error.txt"), message);
throw new ApplicationException(message);
}
} [DllImport("Kernel32")]
private static extern bool SetConsoleCtrlHandler(HandlerRoutine handler, bool add); // A delegate type to be used as the handler routine
// for SetConsoleCtrlHandler.
private delegate bool HandlerRoutine(CtrlTypes ctrlType); // An enumerated type for the control messages
// sent to the handler routine.
private enum CtrlTypes
{
CTRL_C_EVENT = ,
CTRL_BREAK_EVENT,
CTRL_CLOSE_EVENT,
CTRL_LOGOFF_EVENT = ,
CTRL_SHUTDOWN_EVENT
} private static bool ConsoleCtrlCheck(CtrlTypes ctrlType)
{
StopRedis();
return true;
}
}
}

Redis Windows环境安装的更多相关文章

  1. Redis windows环境安装 以及 redis整合spring

    Redis对于Linux是官方支持的,安装和使用没有什么好说的,普通使用按照官方指导,5分钟以内就能搞定.详情请参考: http://redis.io/download Redis官方是不支持wind ...

  2. Redis——windows环境安装redis和redis sentinel部署

    一:Redis的下载和安装 1:下载Redis Redis的官方网站Download页面,Redis提示说:Redis的正式版不支持Windows,要Windows学习Redis,请点击Learn m ...

  3. Redis:在windows环境安装Redis

    Redis:在windows环境安装Redis 第一步: 下载windows版本的Redis:https://github.com/MSOpenTech/Redis. 第二步: 在命令行执行:D:\r ...

  4. PHP XAMPP windows环境安装扩展redis 致命错误: Class 'Redis' not found解决方法

    PHP XAMPP windows环境安装扩展redis 致命错误: Class 'Redis' not found解决方法 1.电脑需要先安装redis服务端环境,并在安装目录下打开客户端redis ...

  5. Windows环境安装tesseract-ocr 4.00并配置环境变量

    最近要做文字识别,不让直接用别人的接口,所以只能尝试去用开源的类库.tesseract-ocr是惠普公司开源的一个文字识别项目,通过它可以快速搭建图文识别系统,帮助我们开发出能识别图片的ocr系统.因 ...

  6. windows环境安装MySQL

    转:https://www.cnblogs.com/ayyl/p/5978418.html windows环境安装MySQL mySQL下载链接:MySQL Installer 5.7 :http:/ ...

  7. Windows环境安装MySQL数据库

    Windows环境安装MySQL数据库 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 最近在学习Java语言,开发环境在Windows操作系统上,因此需要在Windows上安装My ...

  8. MongoDB(二):在Windows环境安装MongoDB

    1. 在Windows环境安装 1.1 MongoDB下载 要在Windows上安装MongoDB,首先打开MongoDB官网:https://www.mongodb.com/download-cen ...

  9. window安装reidis完成之后,想要把数据存入redis,必须开扩展,不然报错,redis windows phpstudy 安装扩展

    redis windows phpstudy 安装扩展   1.http://windows.php.net/downloads/pecl/releases/redis/3.1.5rc1/ 2.htt ...

随机推荐

  1. ObservableCollection<T> 的同类 ListCollectionView

    1:ListCollectionView : CollectionView : INotifyCollectionChanged, INotifyPropertyChanged  2:Observab ...

  2. Learn Rails5.2- ActiveRecord: Migration , spring的使用(不兼容的解决办法)

    偶然一次: 运行rails generate停止不动,网上查找答案,可能是bundle update 之后 spring 版本变化了,和正在运行的 spring 实例不兼容. Spring导致的同样的 ...

  3. 由 '' in 'abc' return True 引发的思考----Python 成员测试操作

    最近遇到判断字典中是否存在空字符串‘’,这个很好判断,直接用:‘’ in ['a','b','c'],就可以直接判断出来:但是当我对字符串使用 “in” 方法进行判断的时候,发现:‘’ in ‘abc ...

  4. 手把手教你如何加入到github的开源世界

    我曾经一直想加入到开源项目中,但是因为没有人指导流程,网上看了很多,基本都是说了个大概,如果你也是一个初出茅庐的人,那么,我将以自己提交的一次开源代码为例,教会你步入开源的世界. 1,首先登陆到htt ...

  5. dbms_job.submit方式创建job,太老了

    --方法一declarejobno number;    begin   dbms_job.submit(jobno,   'xxxx;',    xxxx,    'xxxx');   commit ...

  6. 【css】 文本超出2行显示省略号

    首先,要知道css的三条属性. overflow:hidden; //超出的文本隐藏 text-overflow:ellipsis; //溢出用省略号显示 white-space:nowrap; // ...

  7. python 列表构造时的引用问题

    以前老是不注意python对象引用,平时也没遇到这样的问题,昨天在这个小问题纠结了半天时间.真是TMD啊 先说明一下我的目的,我有一个包含16个元素的列表,每个元素也是一个小列表.我想每四个子列表为一 ...

  8. 修改Oracle归档日志方法

    修改Oracle归档日志的方法 Oracle默认安装的归档日志只有50M,在做大量操作的时候会经常切换日志文件,造成性能问题,下面是具体操作方法 1. 下面是查看现有归档日志大小:   SQL> ...

  9. 【传输协议】发送https请求,由于客户端jdk版本过高,服务端版本低。导致异常:javax.net.ssl.SSLHandshakeException: Server chose SSLv3, but that protocol version is not enabled or not supported by the client.

    本地环境jdk为1.8,服务器使用jdk版本未知.但发送https请求,抛出如下异常,解决方案. 一:发送异常内容如下 javax.net.ssl.SSLHandshakeException: Ser ...

  10. LG5024 保卫王国

    题意 题目描述 Z 国有\(n\)座城市,\(n - 1\)条双向道路,每条双向道路连接两座城市,且任意两座城市 都能通过若干条道路相互到达. Z 国的国防部长小 Z 要在城市中驻扎军队.驻扎军队需要 ...