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. UTF-8里包括GB2312

    用最易懂的说法就是UTF-8里包括GB2312.UTF-8是国际通用的标准(包括世界所有的语言),而GB2312(只是简体中文)只适合做中文的网站. 假设你想做个中文网页,但是还可以翻成英文的话,就得 ...

  2. python numpy 学习

    例子 >>> import numpy as np >>> a = np.arange(15).reshape(3, 5) >>> a array ...

  3. python re 正则表达式复习

    正则表达式是一种小巧的独立语言,用于字符串的匹配 一.元字符 1.. 匹配除换行符外的任意字符 2.^ 匹配字符串开头 3.$ 匹配字符串末尾 4.* 匹配前一字符n次 5.+ 匹配前一字符1-n次 ...

  4. hdu 3264 09 宁波 现场 E - Open-air shopping malls 计算几何 二分 圆相交面积 难度:1

    Description The city of M is a famous shopping city and its open-air shopping malls are extremely at ...

  5. <NET CLR via c# 第4版>笔记 第9章 参数

    9.1 可选参数和命名参数 class Program { private static int s_n = 0; private static void M(int x = 9, string s ...

  6. 论integer是地址传递还是值传递(转)

    原文链接:http://blog.csdn.net/witsmakemen/article/details/46874717 论integer是地址传递还是值传递 Integer 作为传参的时候是地址 ...

  7. centos7上systemd详解

    centos7上systemd详解  发表于 2016-06-07 |  分类于 linux CentOS 7继承了RHEL 7的新的特性,例如强大的systemd, 而systemd的使用也使得以往 ...

  8. BZOJ4408: [Fjoi 2016]神秘数【主席树好题】

    Description 一个可重复数字集合S的神秘数定义为最小的不能被S的子集的和表示的正整数.例如S={1,1,1,4,13}, 1 = 1 2 = 1+1 3 = 1+1+1 4 = 4 5 = ...

  9. Maven与eclipse整合

    版权声明: https://blog.csdn.net/zdp072/article/details/37355993 一. 创建Java项目 第1步:首先导入前面命令行建立的两个maven项目Hel ...

  10. table中tr间距的设定table合并单元格 colspan(跨列)和rowspan(跨行)

    table中的tr的默认display:table-row,虽然可以修改为display:block但是就失去了tr特有的显示效果,如(td自动对齐): 并且在tr中对起设定padding是有用的,可 ...