【发布时间】:2015-01-03 01:05:51
【问题描述】:
下面的代码在 redis 中设置一个键,如果它不存在,则它具有一个到期期限,如果键已经存在,则每次递增它的值,当我尝试递增键的现有值时,代码会给出一个异常,即是当它进入 'If' 块
异常消息:值不是整数或超出范围,sPort:51814,LastCommand:
public bool SetKeyInRedis(string Id, double Amount)
{
bool b = false;
try
{
string Key = "Id:" + Id;
using (var redisClient = new RedisClient(RedisIPAddress,RedisPortNo))
{
if (redisClient.Exists(Key) == 1)
{
redisClient.IncrByFloat(Key, Amount);
b = true;
}
else if (redisClient.Exists(Key) == 0)
{
DateTime Today = DateTime.Now;
DateTime EndOfMonth = new DateTime(Today.Year, Today.Month, DateTime.DaysInMonth(Today.Year, Today.Month));
b = redisClient.Set<double>(Key, Amount, EndOfMonth);
}
else
{
//to-do
}
}
}
catch (Exception Ex)
{
Console.WriteLine(Ex.Message);
}
return b;
}
【问题讨论】:
标签: c# c#-4.0 redis servicestack.redis