Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Operation against a key holding the wrong kind of value in redis when pushing data on a list

Created redis list and setting key like following getting me error

      public async Task MyMethod<T>()
                {
//if i'm doing following it is working
  string listname = "listname";
                    string listkey = "key";
                    RedisList<string> demodemo = new RedisList<string>(Settings, listname);
                    await demodemo.LeftPush(listkey);

//but i want to do it like below it is thoughing exception
            RedisList<string> list = new RedisList<string>(Settings, typeof(T).Name.ToString());
    string mykey = "myId";
    await list.LeftPush(mykey);

getting following error :

Result Message: StackExchange.Redis.RedisServerException : ERR Operation against a key holding the wrong kind of value

like image 701
Neo Avatar asked Sep 02 '15 11:09

Neo


People also ask

What is key in Redis?

Redis Keys are Ideal for Keeping Track of Lots of Strings. For the (simple string) key-value data type Redis allows you to set, get, delete, and increment arbitrary string <key, value> pairs.

How do I delete all Redis keys?

There are two major commands to delete the keys present in Redis: FLUSHDB and FLUSHALL. We can use the Redis CLI to execute these commands. The FLUSHDB command deletes the keys in a database. And the FLUSHALL command deletes all keys in all databases.

What is a Redis set?

Redis sets are unordered collections of unique strings that act like the sets from your favorite programming language (for example, Java HashSets, Python sets, and so on). With a Redis set, you can add, remove, and test for existence O(1) time (in other words, regardless of the number of set elements).


1 Answers

As a side note; RedisList<T> is not a SE.Redis type, so I can't comment on that directly. However: that error message comes from redis-server itself when you try to do things that don't make sense; for example, if foo is a string, you can't lpop foo or zcard foo.

So the question becomes: what is the value that is stored? I can't answer that for you, but: the server can. If you are familiar with redis-cli, then debug object foo or object encoding foo might be useful. Although to be honest, you'll probably do just as well by guessing:

  • strlen foo - if this works, it is a string
  • hlen foo - if this works, it is a hash
  • llen foo - if this works, it is a list
  • scard foo - if this works, it is a set
  • zcard foo - if this works, it is a sorted-set

Note that all of these commands are available via SE.Redis, but for investigating a suspect database, redis-cli is usually easier.

What has probably happened is you've accidentally reused a key name without realizing it. Which is perhaps a great advertisement for the value of adding a prefix to your key names - something else that SE.Redis can do for you automatically when talking to a database.

like image 110
Marc Gravell Avatar answered Oct 28 '22 15:10

Marc Gravell