Search code examples
c#c#-4.0redisbooksleeve

Redis HashKey erroring out


I created a HaskKey using Boolsleve c#, i am providing a unique field each time and my item is Json string.

   public virtual void AddHashSetKey(string item, string hashField)
    {
        _redisClient.Hashes.Set(_database, Key, hashField, item);
    }

After adding about thousands fields (141988) i try to check the number of fields in the hash key but get error below. not sure where i can find more details or why am i getting this error?

redis 127.0.0.1:6379[1]> Exists C:
(integer) 1
redis 127.0.0.1:6379[1]> HLEN C:
(error) ERR Operation against a key holding the wrong kind of value
redis 127.0.0.1:6379[1]>

Solution

  • Well, I've looked locally, and it works fine. The main thoughts I have:

    • are you in the correct database? (select in redis terms)
    • is it possible that C: already had a non-hash value, and therefore the value could not actually be set in the first place? Calling any hash command (including hset) will fail if the value is not a hash - so if it already exists as a string: bad things
    • are you checking the correct key? (noting that keys are case-sensitive)
    • in particular, I notice that you aren't checked for errors; since BookSleeve is fully asynchronous, it cannot tell you about server-side errors when you call Set; any error will be exposed (when it arrives) via the Task API, via any of await, .Wait(), .Result or .ContinueWith() (or any other Task API of your choice)

    But locally:

    redis 127.0.0.1:6379[1]> exists C:
    (integer) 1
    redis 127.0.0.1:6379[1]> hlen C:
    (integer) 1
    redis 127.0.0.1:6379[1]> hgetall C:
    1) "someField"
    2) "{foo:'bar'}"
    

    You might also want to try:

    redis 127.0.0.1:6379[1]> type C:
    hash
    

    which tells you what type of data is stored at C: