本文整理汇总了C#中StackExchange.Redis.ConfigurationOptions.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# ConfigurationOptions.ToString方法的具体用法?C# ConfigurationOptions.ToString怎么用?C# ConfigurationOptions.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StackExchange.Redis.ConfigurationOptions
的用法示例。
在下文中一共展示了ConfigurationOptions.ToString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Connect
public static ConnectionMultiplexer Connect(RedisConfiguration configuration)
{
string connectionString = configuration.ConnectionString;
if (string.IsNullOrWhiteSpace(configuration.ConnectionString))
{
Func<RedisConfiguration, string> createConfigurationOptions = (config) =>
{
var configurationOptions = new ConfigurationOptions()
{
AllowAdmin = config.AllowAdmin,
ConnectTimeout = config.ConnectionTimeout,
Password = config.Password,
Ssl = config.IsSsl,
SslHost = config.SslHost,
ConnectRetry = 10,
AbortOnConnectFail = false
};
foreach (var endpoint in configuration.Endpoints)
{
configurationOptions.EndPoints.Add(endpoint.Host, endpoint.Port);
}
return configurationOptions.ToString();
};
connectionString = createConfigurationOptions(configuration);
}
ConnectionMultiplexer connection;
lock (connectLock)
{
if (!connections.TryGetValue(connectionString, out connection))
{
var builder = new StringBuilder();
using (var log = new StringWriter(builder, CultureInfo.InvariantCulture))
{
connection = ConnectionMultiplexer.Connect(connectionString, log);
}
connection.ConnectionFailed += (sender, args) =>
{
connections.Remove(connectionString);
};
if (!connection.IsConnected)
{
throw new InvalidOperationException("Connection failed.\n" + builder.ToString());
}
connection.PreserveAsyncOrder = false;
connections.Add(connectionString, connection);
}
}
return connection;
}
示例2: Main
static void Main(string[] args)
{
var opts = new ConfigurationOptions();
opts.ClientName = "Test-Clinet";
opts.KeepAlive = 180;
opts.Password = "123456";
Console.WriteLine(opts.ToString());
var db = _redisClient.GetDatabase();
db.StringSet("Key", Guid.NewGuid().ToString());
var value = db.StringGet("Key");
Console.WriteLine(value);
Console.WriteLine("\nPress Any Key To Exit...");
Console.ReadLine();
}
示例3: GetRedisConnectionString
public static string GetRedisConnectionString()
{
var settings = ParseVCAP();
ConfigurationOptions config = new ConfigurationOptions
{
EndPoints =
{
{ settings.RedisHost, int.Parse(settings.RedisPort)}
},
CommandMap = CommandMap.Create(new HashSet<string>
{ // EXCLUDE a few commands
/*"INFO", "CONFIG", "CLUSTER",
"PING", "ECHO", "CLIENT"*/
}, available: false),
KeepAlive = 180,
DefaultVersion = new Version(2, 8, 8),
Password = settings.RedisPassword
};
return config.ToString();
}
示例4: SingletonRedisConnection
//public SingletonRedisConnection()
//{
// this.redisConnectionString = "";
//}
public SingletonRedisConnection(ConfigurationOptions options)
{
this.redisConnectionString = options.ToString();
}