1

I've to store redis key and value in redis chache. However the redisValue which I want to save is a Json string of 1976 characters length which has-> {,},[,],",-,: characters apart from numbers,alphabets. but while storing it says invalid argument.

So are any of above characters not allowed in redisValue or is there any character limit? Or what could be possible reasons for invalid argument exception for redisvalue ?

Thanks in advance.

Akshay Kale
  • 53
  • 1
  • 5
  • if you're seeing invalid argument: I'd be interested in seeing any sample code here showing when you're seeing this (context: I'm a primary maintainer of SE.Redis). For "what could be possible reasons", I'd really need to see code. – Marc Gravell Mar 30 '23 at 18:44
  • in Ubuntu. I've initiated redis-cli, after that below command->set "redisKey" "RedisValueJson" when I press enter it shows "Invalid Argument(s)" error – Akshay Kale Mar 30 '23 at 18:51
  • 1
    right; so that's something *completely different*; you're not using C#, .NET, etc; you're using an entirely different thing; redis-cli *needs string escaping*, because it uses optional quoted syntax i.e so that in the command `set redisKey "a b c"`, we pass two parameters not four; it is *this escaping* that you are hitting - but this has *nothing whatsoever* with what redis can actually store - this is simply a limitation of redis-cli; IIRC it is C-style escaping, so I'm guessing `"a\"b\"c` would insert quote values into the value. Doing this for JSON would be tedious; but again: this is – Marc Gravell Mar 31 '23 at 06:03
  • *purely* a feature of redis-cli, *not* of redis or any particular redis client (well, I guess you could say it is a RESP1 limitation, but most clients talk RESP2/RESP3; redis-cli is intended for humans, not machines, so it uses a different approach) – Marc Gravell Mar 31 '23 at 06:04

2 Answers2

0

Assuming RedisValue here is from StackExchange.Redis; it is treated as opaque data transferred using the binary-safe API; there are no disallowed characters. For limits: things always get hairy for extremely large strings, due to the 2GB limit of .NET objects (including string instances), but: you're nowhere near that. Internally, redis may have a 512MiB limit, which is on the UTF-8 encoded value.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
0

-> redis cli does not allow to enter double quotes directly. We've either use the escape sequence for it or we've to replace the double quotes with any other character and then insert it. In my case, I replaced the double quotes with $ and I was able to add json as a redisValue.

ThankYou all for the help

Akshay Kale
  • 53
  • 1
  • 5