本文整理汇总了C#中RedisClient.Get方法的典型用法代码示例。如果您正苦于以下问题:C# RedisClient.Get方法的具体用法?C# RedisClient.Get怎么用?C# RedisClient.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedisClient
的用法示例。
在下文中一共展示了RedisClient.Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecTests
public void ExecTests()
{
var okReply = "+OK\r\n";
using(var mock = new MockConnector("localhost", 9999, okReply, "+QUEUED\r\n", "+QUEUED\r\n", "*2\r\n" + okReply + okReply))
using(var redis = new RedisClient(mock))
{
int x = 0;
using(var tran = redis.BeginTransaction())
{
Assert.Equal("*1\r\n$5\r\nMULTI\r\n", mock.GetMessage());
tran.On(tran.Set("key1", "value1"), r =>
{
Assert.True(r);
x += 1;
});
Assert.Equal("*3\r\n$3\r\nSET\r\n$4\r\nkey1\r\n$6\r\nvalue1\r\n", mock.GetMessage());
tran.On(tran.Set("key2", "value2"), r =>
{
Assert.True(r);
Assert.Equal(1, x);
x += 2;
});
Assert.Equal("*3\r\n$3\r\nSET\r\n$4\r\nkey2\r\n$6\r\nvalue2\r\n", mock.GetMessage());
tran.Commit();
Assert.Equal("*1\r\n$4\r\nEXEC\r\n", mock.GetMessage());
}
Assert.Equal(string.Empty, mock.GetMessage());
Assert.Equal(3, x);
}
this.RealCall(redis =>
{
int x = 0;
using(var tran = redis.BeginTransaction())
{
tran.On(tran.Set("key1", "value1"), r =>
{
Assert.True(r);
x += 1;
});
tran.On(tran.Set("key2", "value2"), r =>
{
Assert.True(r);
Assert.Equal(1, x);
x += 2;
});
tran.Commit();
}
Assert.Equal(3, x);
Assert.Equal("value1", (string)redis.Get("key1"));
Assert.Equal("value2", (string)redis.Get("key2"));
});
}
示例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: Acquiring_lock_with_timeout
public void Acquiring_lock_with_timeout()
{
var redisClient = new RedisClient(TestConfig.SingleHost);
//Initialize and set counter to '1'
redisClient.IncrementValue("atomic-counter");
//Acquire lock and never release it
redisClient.AcquireLock("testlock");
var waitFor = TimeSpan.FromSeconds(2);
var now = DateTime.Now;
try
{
using (var newClient = new RedisClient(TestConfig.SingleHost))
{
//Attempt to acquire a lock with a 2 second timeout
using (newClient.AcquireLock("testlock", waitFor))
{
//If lock was acquired this would be incremented to '2'
redisClient.IncrementValue("atomic-counter");
}
}
}
catch (TimeoutException tex)
{
var timeTaken = DateTime.Now - now;
Console.WriteLine("After '{0}', Received TimeoutException: '{1}'", timeTaken, tex.Message);
var counter = redisClient.Get<int>("atomic-counter");
Console.WriteLine("atomic-counter remains at '{0}'", counter);
}
}
示例4: Does_retry_failed_commands
public void Does_retry_failed_commands()
{
//LogManager.LogFactory = new ConsoleLogFactory(debugEnabled: true);
RedisStats.Reset();
var redisCtrl = new RedisClient(RedisConfig.DefaultHost);
redisCtrl.FlushAll();
redisCtrl.SetClient("redisCtrl");
var redis = new RedisClient(RedisConfig.DefaultHost);
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: 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"));
}
}
示例6: 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));
}
示例7: ReadPopulationCount
public int ReadPopulationCount(Guid tileId)
{
var client = new RedisClient();
var key = new PeopleKeys ().GetPopulationKey (tileId);
var value = client.Get (key);
return Convert.ToInt32(value);
}
示例8: Throws_on_access_of_6100_operations
public void Throws_on_access_of_6100_operations()
{
using (var client = new RedisClient(TestConfig.SingleHost))
{
Assert.Throws<LicenseException>(() =>
6100.Times(() => client.Get("any key")));
}
}
示例9: Allows_access_of_any_number_of_operations
public void Allows_access_of_any_number_of_operations(int times)
{
using (var client = new RedisClient(TestConfig.SingleHost))
{
times.Times(() => client.Get("any key"));
Assert.Pass();
}
}
示例10: GetTest
public void GetTest()
{
using (IRedisClient client = new RedisClient("localhost", ReidsDefaultTcpPort, 12))
{
Assert.IsTrue(client.Set("TestName2", "TestValue2"));
Assert.AreEqual(client.Get("TestName2"), "TestValue2");
Assert.IsTrue(client.Connected);
}
}
示例11: Set_key_Expire
public void Set_key_Expire()
{
var key = "Set_key_Expire";
using (var rcClient = new RedisClient(ip, port))
{
rcClient.Set(key, key, 5);
var info1 = rcClient.Get(key);
Assert.AreEqual(info1.ToString(), key);
Thread.Sleep(6000);
var info2 = rcClient.Get(key);
Assert.AreEqual(info2, "");
}
}
示例12: GetTest
public void GetTest()
{
using(var mock = new MockConnector("localhost", 9999, "$5\r\nhello\r\n"))
using(var redis = new RedisClient(mock))
{
Assert.Equal("hello", (string)redis.Get("key"));
Assert.Equal("*2\r\n$3\r\nGET\r\n$3\r\nkey\r\n", mock.GetMessage());
}
}
示例13: Set_Get_key
public void Set_Get_key()
{
var key = "Set_Get_key";
using (var rcClient = new RedisClient(ip, port))
{
rcClient.Set(key, key);
var info2 = rcClient.Get(key);
Assert.AreEqual(info2.ToString(), key);
}
}
示例14: Continuation_Set_Get_ByDifferentClient
public void Continuation_Set_Get_ByDifferentClient()
{
for (int i = 0; i < 1000; i++)
{
using (var rcClient = new RedisClient(ip, port))
{
rcClient.Set("Continuation_Set_Get_ByDifferentClient" + i, i.ToString(), 10);
rcClient.Get("Continuation_Set_Get_ByDifferentClient" + i);
rcClient.Send(RedisCommand.INFO);
}
}
}
示例15: Search_Test
public void Search_Test()
{
using (var client = new RedisClient(TestConfig.SingleHost))
{
const string cacheKey = "urn+metadata:All:SearchProProfiles?SwanShinichi Osawa /0/8,0,0,0";
const long value = 1L;
client.Set(cacheKey, value);
var result = client.Get<long>(cacheKey);
Assert.That(result, Is.EqualTo(value));
}
}