簡體   English   中英

將Redis與C#一起使用時出錯:值不是整數或超出范圍,sPort:51410,LastCommand:

[英]Error when using Redis with C# : value is not an integer or out of range, sPort: 51410, LastCommand:

下面的代碼在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;
    }

找出解決方案:

我使用的是Redis所有必需的ServiceStack dll的舊版本,下載了所有必需的dll的新版本,並且現在可以正常使用了。

INCRBYFLOAT期望增量為浮點數,而不是兩倍。

傳遞float amount ,而不是double amount因為此命令可能不支持double。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM