gpt4 book ai didi

.net - Hash.Remove 上的 string[] 异常

转载 作者:IT王子 更新时间:2023-10-29 06:04:05 24 4
gpt4 key购买 nike

当尝试通过调用 RedisConnection.Hashes.Remove(int db, string key, string[] fields, bool queueJump = false) 删除散列的字段时,我得到一个异常提示:“ERR wrong number of arguments for 'hdel' command ".

这是生成它的代码:

    static void Main(string[] args)
{
var connection = new RedisConnection("localhost");
connection.Open();

var transaction = connection.CreateTransaction();

// setting values to fields - works fine!
for (int index = 0; index < 2; index++)
{
transaction.Hashes.Set(0, "s1", String.Format("f{0}", index.ToString()), String.Format("v{0}", index.ToString()));
}
transaction.Execute().Wait();

// Here is where the exception is being thrown
connection.Hashes.Remove(0, "s1", new string[] { "f1", "f2" }).Wait();

Console.ReadLine();
}

我正在使用取自 nuget 的 Booksleeve 1.3.37.0。谢谢,

最佳答案

来自HDEL manual ;

History

= 2.4: Accepts multiple field arguments. Redis versions older than 2.4 can only remove a field per call.

换句话说,您运行的 Redis 版本早于 2.4,因此每次调用只能删除一个字段。这很可能会奏效;

connection.Hashes.Remove(0, "s1", new string[] { "f1" }).Wait();
connection.Hashes.Remove(0, "s1", new string[] { "f2" }).Wait();

(或者当然可能有一个不采用数组的调用版本)

关于.net - Hash.Remove 上的 string[] 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16776909/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com