StackExchange.Redis - Configuration

欲連線至 Redis,需先設定 Configutaion,在 StackExchange.Redis 提供兩種設定方式,一種是用 ConfigurationOptions 物件直接宣告設定:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using StackExchange.Redis; 
...
var configuration = new ConfigurationOptions()
{
EndPoints = {
{"localhost", 6379},
{"localhost", 6380}
},
Password = "LarryNung"
};
using (var conn = ConnectionMultiplexer.Connect(configuration))
{
...
}
...


一種是透過字串的方式設定:

1
2
3
4
5
6
7
8
using StackExchange.Redis; 
...
var configuration = "localhost:6379,localhost:6380,password=LarryNung";
using (var conn = ConnectionMultiplexer.Connect(configuration))
{
...
}
...


如果不清楚有哪些可供設定,可參閱下表: