2

When trying to delete hash's fields by calling RedisConnection.Hashes.Remove(int db, string key, string[] fields, bool queueJump = false) I get an exception saying: "ERR wrong number of arguments for 'hdel' command".

Here is a code that produces it:

    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();
    }

I'm using Booksleeve 1.3.37.0 taken from nuget. Thanks,

  • Hmmm.... that's odd; the code actually includes a version-detection test here, to ensure the correct (varadic/non-varadic) version is used. Can you indicate exactly what server version you are using, so I can try to repro? – Marc Gravell May 28 '13 at 15:18

2 Answers2

3

From the HDEL manual;

History

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

In other words, you're running a Redis version older than 2.4 so you can only remove one field per call. Most likely, this will work;

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

(or there may of course be a version of the call that does not take an array)

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
1

BookSleeve does perform version testing to try to hide these subtleties from you; it seems that the problem is in the version-test itself:

    /// <summary>
    /// Does HDEL support varadic usage?
    /// </summary>
    public bool HashVaradicDelete { get { return version > v2_2_0; } }

I guess that should be:

    /// <summary>
    /// Does HDEL support varadic usage?
    /// </summary>
    public bool HashVaradicDelete { get { return version >= v2_4_0; } }

Reading the comments at the bottom of HDEL, it seems that the page didn't list the version very clearly at some point - I probably got my version test from the comment:

The current official stable version (2.2) doesn't support multiple fields; I just chased my tail for a while trying to get it to work, until I realized this page is the documentation for 2.4, not 2.2

I'm happy to change that to >= 2.4 - but can you confirm exactly what server version you are using?

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • +1 for version checks that just speed up, not break the API :) – Joachim Isaksson May 28 '13 at 15:28
  • @JoachimIsaksson that probably comes, in part, because for a long time we were a few versions behind - and I wanted it to "just work" but get silently faster as we upgraded. The `TakeLock` is another good example of this - the implementation of that changes radically between versions – Marc Gravell May 28 '13 at 15:34