本文整理汇总了C#中RedisClient类的典型用法代码示例。如果您正苦于以下问题:C# RedisClient类的具体用法?C# RedisClient怎么用?C# RedisClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RedisClient类属于命名空间,在下文中一共展示了RedisClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAuth
public void TestAuth()
{
using (var redis = new RedisClient(Host, Port, 0))
{
Assert.AreEqual("OK", redis.Auth(Password));
}
}
示例2: ValidateTransfer
public string ValidateTransfer(string sourceAppId, string userId, string transferId, string transferToken)
{
var red = new RedisClient<string>();
var result = red.Get("transfertoken:" + transferId);
if (!string.IsNullOrEmpty(result))
{
var redResult = red.Del("transfertoken:" + transferId);
var redapp = new RedisClient<AppRegistry>();
redapp.Select(1);
var app = redapp.Get(HttpContext.Current.Items["AppId"] as string);
var str = "UserId=" + userId + "&TransferId=" + transferId + "&Salt=" + app.AppSecret ;
str = Hash.GetHash(str, Hash.HashType.SHA256);
if (transferToken != str)
{
throw new FaultException<UnauthorizedAccessException>(new UnauthorizedAccessException("token yanlış"));
}
string sessionguid = Guid.NewGuid().ToString();
var redis = new RedisClient<Common.SessionRegistry>();
var appId = HttpContext.Current.Items["AppId"] as string;
redis.Set(sessionguid, new SessionRegistry() { SessionCookie = sessionguid, AppId = appId, UserId = userId });
return sessionguid;
}
return null;
}
示例3: OnTestFixtureSetUp
public void OnTestFixtureSetUp()
{
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
redisClient.FlushAll();
}
}
示例4: Does_retry_failed_commands_auth
public void Does_retry_failed_commands_auth()
{
// -> Redis must have "requirepass testpassword" in config
var connstr = "[email protected]";
RedisStats.Reset();
var redisCtrl = new RedisClient(connstr); //RedisConfig.DefaultHost
redisCtrl.FlushAll();
redisCtrl.SetClient("redisCtrl");
var redis = new RedisClient(connstr);
redis.SetClient("redisRetry");
var clientInfo = redisCtrl.GetClientsInfo();
var redisId = clientInfo.First(m => m["name"] == "redisRetry")["id"];
Assert.That(redisId.Length, Is.GreaterThan(0));
Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(1));
redis.OnBeforeFlush = () =>
{
redisCtrl.KillClients(withId: redisId);
};
Assert.That(redis.IncrementValue("retryCounter"), Is.EqualTo(2));
Assert.That(redis.Get<int>("retryCounter"), Is.EqualTo(2));
Assert.That(RedisStats.TotalRetryCount, Is.EqualTo(1));
Assert.That(RedisStats.TotalRetrySuccess, Is.EqualTo(1));
Assert.That(RedisStats.TotalRetryTimedout, Is.EqualTo(0));
}
示例5: Working_with_int_values
public void Working_with_int_values()
{
const string intKey = "intkey";
const int intValue = 1;
//STORING AN INT USING THE BASIC CLIENT
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
redisClient.SetEntry(intKey, intValue.ToString());
string strGetIntValue = redisClient.GetValue(intKey);
int toIntValue = int.Parse(strGetIntValue);
Assert.That(toIntValue, Is.EqualTo(intValue));
}
//STORING AN INT USING THE GENERIC CLIENT
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
//Create a generic client that treats all values as ints:
IRedisTypedClient<int> intRedis = redisClient.GetTypedClient<int>();
intRedis.SetEntry(intKey, intValue);
var toIntValue = intRedis.GetValue(intKey);
Assert.That(toIntValue, Is.EqualTo(intValue));
}
}
示例6: OnBeforeEachTest
public virtual void OnBeforeEachTest()
{
if (Redis != null) Redis.Dispose();
Redis = new RedisClient(TestConfig.SingleHost);
Redis.FlushDb();
RedisTyped = Redis.As<CacheRecord>();
}
示例7: Send
public void Send(TransportMessage message, Address address)
{
using(var redisClient = new RedisClient())
{
redisClient.Add(string.Format("{0}:{1}", address.Machine, address.Queue), message);
}
}
示例8: UseClient
private static void UseClient(RedisClient client, int clientNo)
{
var host = "";
try
{
host = client.Host;
Log("Client '{0}' is using '{1}'", clientNo, client.Host);
var testClientKey = "test:" + host + ":" + clientNo;
client.SetEntry(testClientKey, testData);
var result = client.GetValue(testClientKey) ?? "";
Log("\t{0} => {1} len {2} {3} len", testClientKey,
testData.Length, testData.Length == result.Length ? "==" : "!=", result.Length);
}
catch (NullReferenceException ex)
{
Console.WriteLine("NullReferenceException StackTrace: \n" + ex.StackTrace);
}
catch (Exception ex)
{
Console.WriteLine("\t[[email protected]{0}]: {1} => {2}",
host, ex.GetType().Name, ex.Message);
}
}
示例9: Can_support_64_threads_using_the_client_simultaneously
public void Can_support_64_threads_using_the_client_simultaneously()
{
var before = Stopwatch.GetTimestamp();
const int noOfConcurrentClients = 64; //WaitHandle.WaitAll limit is <= 64
#if NETCORE
List<Task> tasks = new List<Task>();
#else
var clientAsyncResults = new List<IAsyncResult>();
#endif
using (var redisClient = new RedisClient(TestConfig.SingleHost))
{
for (var i = 0; i < noOfConcurrentClients; i++)
{
var clientNo = i;
var action = (Action)(() => UseClientAsync(redisClient, clientNo));
#if NETCORE
tasks.Add(Task.Run(action));
#else
clientAsyncResults.Add(action.BeginInvoke(null, null));
#endif
}
}
#if NETCORE
Task.WaitAll(tasks.ToArray());
#else
WaitHandle.WaitAll(clientAsyncResults.ConvertAll(x => x.AsyncWaitHandle).ToArray());
#endif
Debug.WriteLine(String.Format("Time Taken: {0}", (Stopwatch.GetTimestamp() - before) / 1000));
}
示例10: CreateClient
private IRedisClient CreateClient(bool flushAll = true)
{
var client = new RedisClient(6379);
if(flushAll)
client.FlushAll();
return client;
}
示例11: Connect
public void Connect()
{
// note: defaults to 127.0.0.1:6379
using(dynamic client = new RedisClient())
{
}
}
示例12: Allows_access_of_6000_operations
public void Allows_access_of_6000_operations()
{
using (var client = new RedisClient(TestConfig.SingleHost))
{
6000.Times(() => client.Get("any key"));
}
}
示例13: Save
public void Save(EngineInfo info)
{
var client = new RedisClient();
var key = new EngineKeys ().GetInfoKey (info.Id);
var json = info.ToJson ();
client.Set(key, json);
}
示例14: RedisCacheService
static RedisCacheService()
{
Redis = new RedisClient("localhost");
string ping = Redis.Ping();
JsConfig.DateHandler = DateHandler.ISO8601;
}
示例15: CreateServer
RedisMqServer CreateServer()
{
using (var redis = new RedisClient())
redis.FlushAll();
var mqServer = new RedisMqServer(new BasicRedisClientManager());
mqServer.RegisterHandler<Spin0>(m => new Spin0 { Id = counter.Spin0++ });
mqServer.RegisterHandler<Spin10>(m => {
var sw = Stopwatch.StartNew();
while (sw.ElapsedMilliseconds < 10) Thread.SpinWait(100000);
return new Spin10 { Id = counter.Spin10++ };
});
mqServer.RegisterHandler<Spin100>(m => {
var sw = Stopwatch.StartNew();
while (sw.ElapsedMilliseconds < 100) Thread.SpinWait(100000);
return new Spin100 { Id = counter.Spin100++ };
});
mqServer.RegisterHandler<Spin1000>(m => {
var sw = Stopwatch.StartNew();
while (sw.ElapsedMilliseconds < 1000) Thread.SpinWait(100000);
return new Spin1000 { Id = counter.Spin1000++ };
});
return mqServer;
}