本文整理汇总了C#中RedisClient.Auth方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Auth方法的具体用法?C# RedisClient.Auth怎么用?C# RedisClient.Auth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Auth方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Initialize
private void Initialize()
{
try
{
// create the connection
Client = new RedisClient(_config.Host, _config.Port)
{
ReconnectAttempts = 3,
ReconnectTimeout = 200
};
// select the database
Client.Select(_config.DatabaseId);
// authenticate if needed.
if (!string.IsNullOrEmpty(_config.Password))
Client.Auth(_config.Password);
// check the version
var version = GetVersion();
if (version < _requiredMinimumVersion)
throw new Exception(string.Format("You are using redis version {0}, minimum required version is 2.6", version));
_logger.Information("Redis storage initialized: {0:l}:{1}, v{2:l}.", _config.Host, _config.Port, version);
}
catch (Exception e)
{
_logger.Error("Redis storage initialization failed: {0:l}:{1} - {2:l}", _config.Host, _config.Port, e.Message);
}
}
示例2: TestAuth
public void TestAuth()
{
using (var redis = new RedisClient(Host, Port, 0))
{
Assert.AreEqual("OK", redis.Auth(Password));
}
}
示例3: TestUnwatch
public void TestUnwatch()
{
using (new RedisTestKeys(Redis, "test1"))
{
Redis.Watch("test1");
Assert.AreEqual("OK", Redis.Unwatch());
Redis.Multi();
using (var otherClient = new RedisClient(Host, Port, 0))
{
otherClient.Auth(Password);
otherClient.Set("test1", "other");
}
Redis.Set("test1", "multi");
Assert.IsNotNull(Redis.Exec());
}
}
示例4: TestSubscribe
public void TestSubscribe()
{
int change_count = 0;
int message_count = 0;
string last_message = String.Empty;
using (var redisConsumer = new RedisClient(Host, Port, 0))
using (var redisPublisher = new RedisClient(Host, Port, 0))
{
redisConsumer.Auth(Password);
redisPublisher.Auth(Password);
redisConsumer.SubscriptionReceived += (o, e) =>
{
message_count++;
last_message = e.Message.Body;
};
redisConsumer.SubscriptionChanged += (o, e) =>
{
change_count++;
};
Task consumer_task = Task.Factory.StartNew(() =>
{
redisConsumer.Subscribe("test");
});
while (change_count != 1) // wait for subscribe
Thread.Sleep(10);
Assert.AreEqual(1, redisPublisher.Publish("test", "hello world"), "First publish");
Assert.AreEqual(0, redisPublisher.Publish("junk", "nothing"), "Junk publish");
Assert.AreEqual(1, redisPublisher.Publish("test", "hello again"), "Second publish");
redisConsumer.Subscribe("test2");
while (change_count != 2) // wait for subscribe
Thread.Sleep(10);
Assert.AreEqual(1, redisPublisher.Publish("test2", "a new channel"), "New channel publish");
redisConsumer.Unsubscribe("test");
redisConsumer.Unsubscribe();
consumer_task.Wait();
Assert.AreEqual(3, message_count);
Assert.AreEqual(4, change_count);
Assert.AreEqual("a new channel", last_message);
}
}
示例5: Initialize
public void Initialize()
{
Host = ConfigurationManager.AppSettings["host"];
Port = Int32.Parse(ConfigurationManager.AppSettings["port"]);
Password = ConfigurationManager.AppSettings["password"];
_redis = new Lazy<RedisClient>(() =>
{
RedisClient redis = new RedisClient(Host, Port, 0);
redis.Auth(Password);
return redis;
});
_async = new Lazy<RedisClientAsync>(() =>
{
RedisClientAsync async = new RedisClientAsync(Host, Port, 0);
async.Auth(Password).Wait();
return async;
});
}