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
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.
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.
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).
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 stringhlen foo
- if this works, it is a hashllen foo
- if this works, it is a listscard foo
- if this works, it is a setzcard foo
- if this works, it is a sorted-setNote 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With