-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRedisConnection.cs
81 lines (75 loc) · 2.84 KB
/
RedisConnection.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using StackExchange.Redis;
namespace redisdotnetdemo
{
public class RedisConnection
{
public static string REDIS_DB_URL;
public static string REDIS_DB_PWD;
private static Lazy<ConfigurationOptions> txnConfigOptions
= new Lazy<ConfigurationOptions>(() =>
{
var configOptions = new ConfigurationOptions();
configOptions.EndPoints.Add(REDIS_DB_URL);
configOptions.Password = REDIS_DB_PWD;
configOptions.AbortOnConnectFail = false;
configOptions.ConnectRetry = 10;
configOptions.KeepAlive = 180;
configOptions.SyncTimeout = 100000;
configOptions.ClientName = "TxnRedisConnection";
configOptions.ConnectTimeout = 1000;
configOptions.Ssl = false;
configOptions.CommandMap = CommandMap.Create(
new HashSet<string>
{ // EXCLUDE a few commands
"SUBSCRIBE", "UNSUBSCRIBE",
"INFO", "CONFIG", "ECHO",
}, available: false);
return configOptions;
});
private static Lazy<ConnectionMultiplexer> TxnlazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect(txnConfigOptions.Value);
});
public static ConnectionMultiplexer Conn_Txn
{
get
{
return TxnlazyConnection.Value;
}
}
private static Lazy<ConfigurationOptions> nonTxnConfigOptions
= new Lazy<ConfigurationOptions>(() =>
{
var configOptions = new ConfigurationOptions();
configOptions.EndPoints.Add(REDIS_DB_URL);
configOptions.Password = REDIS_DB_PWD;
configOptions.AbortOnConnectFail = false;
configOptions.ConnectRetry = 10;
configOptions.KeepAlive = 180;
configOptions.SyncTimeout = 5000;
configOptions.ClientName = "NonTxnRedisConnection";
configOptions.ConnectTimeout = 1000;
configOptions.Ssl = false;
configOptions.CommandMap = CommandMap.Create(
new HashSet<string>
{ // EXCLUDE a few commands
"SUBSCRIBE", "UNSUBSCRIBE",
"INFO", "CONFIG", "ECHO",
}, available: false);
return configOptions;
});
private static Lazy<ConnectionMultiplexer> nonTxnlazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect(nonTxnConfigOptions.Value);
});
public static ConnectionMultiplexer Conn_NonTxn
{
get
{
return nonTxnlazyConnection.Value;
}
}
}
}