Search code examples
apiredishashbooksleeve

Redis Booksleeve - How to use Hash API properly


i am using the Booksleeve hash api for Redis. I am doing the following:

  CurrentConnection.Hashes.Set(0, "item:1", "priority", task.priority.ToString());

  var taskResult = CurrentConnection.Hashes.GetString(0, "item:1", "priority");

  taskResult.Wait();

  var priority = Int32.Parse(taskResult.Result)

However i am getting an Aggregate exception: "ERR Operation against a key holding the wrong kind of value"

I am not sure what i am doing wrong here (except of blocking the task :)).

Note: CurrentConnection is an instance of BookSleeve.RedisConnection

Please help!

Thanks


Solution

  • That is not a Booksleeve issue - it is a redis error; in fact, the full error message you should be seeing is:

    Redis server: ERR Operation against a key holding the wrong kind of value

    (where I try to make it clear that this error has come from redis, not Booksleeve)

    As for what causes this: each key in redis has a designated type; string, hash, list, etc. You cannot use hash operations on something that is not a hash.

    My guess, then, is that "item:1" already exists, but as something other than a hash. I have unit tests that confirm this from Booksleeve (i.e. with/without a pre-existing non-hash value).

    You can investigate this in redis using redis-cli or any other client (telnet works, at a push), with the command:

    type item:1
    

    (thanks @Sripathi)