|
|
@ -13,24 +13,37 @@ namespace RedisStuy
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 客户端操作
|
|
|
|
/// 客户端操作
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public static class RedisHelper
|
|
|
|
public sealed class RedisHelper
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取 Redis连接
|
|
|
|
private static readonly IConnectionMultiplexer connectionMultiplexer = IniConnection();
|
|
|
|
/// (此为共享和线程安全的,可以设计成单例模式)
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
private static IConnectionMultiplexer IniConnection()
|
|
|
|
public static IConnectionMultiplexer GetConnectionMultiplexer()
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
ConfigurationOptions options = new ConfigurationOptions();
|
|
|
|
ConfigurationOptions options = new ConfigurationOptions();
|
|
|
|
|
|
|
|
options.KeepAlive = 200;
|
|
|
|
options.DefaultDatabase = 1;
|
|
|
|
options.DefaultDatabase = 1;
|
|
|
|
options.AllowAdmin = true;
|
|
|
|
options.AllowAdmin = true;
|
|
|
|
options.EndPoints.Add("127.0.0.1", 6379);
|
|
|
|
options.EndPoints.Add("127.0.0.1", 6379);
|
|
|
|
|
|
|
|
|
|
|
|
IConnectionMultiplexer connection = ConnectionMultiplexer.Connect(options);
|
|
|
|
IConnectionMultiplexer connection = ConnectionMultiplexer.Connect(options);
|
|
|
|
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
return connection;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private RedisHelper()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 获取 Redis连接
|
|
|
|
|
|
|
|
/// (此为共享和线程安全的,可以设计成单例模式)
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
public static IConnectionMultiplexer GetConnectionMultiplexer()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return connectionMultiplexer;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 获取 默认Reids服务器
|
|
|
|
/// 获取 默认Reids服务器
|
|
|
|