forked from MarcelRaschke/PostSharp.Samples
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRedisServer.cs
49 lines (42 loc) · 1.17 KB
/
RedisServer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace PostSharp.Samples.Caching
{
internal class RedisServer : IDisposable
{
private Process process;
private RedisServer(Process process)
{
this.process = process;
}
public void Dispose()
{
if (process != null)
{
Console.WriteLine("Stopping Redis server.");
process.Close();
process = null;
}
}
public static RedisServer Start()
{
if (Process.GetProcessesByName("redis-server").Any())
{
Console.WriteLine("Redis has already started.");
}
else
{
var configFile = Path.GetFullPath("redis.conf");
Console.WriteLine("Starting Redis server with config file: " + configFile);
// Update this path if the redis-64 NuGet package is restored to another location.
return new RedisServer(Process.Start(
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
".nuget", "packages", "redis-64", "3.0.503", "tools", "redis-server.exe"),
configFile));
}
return new RedisServer(null);
}
}
}