1

When I save a string to redis using ServiceStack.Redis:

client.Add("key1","abc");

While fetching the value, it returns:

client.GetValue("key1");

it returns

"\"abc\""

How do I get the complete string?

Thanks

Satyajit
  • 1,971
  • 5
  • 28
  • 51
  • Are you sure `client.Add` is the correct method to use? I cannot find it in the documentation. Looks like `client.SetValue` is what you would use. – Hazerd Oct 17 '16 at 08:12
  • Yes, there is a method available called Add. It takes value as object, which is good to create a generic method to pass any value. – Satyajit Oct 17 '16 at 08:22
  • I just tried out the live version. Looks like `client.Add` is adding those quotes, `client.SetValue` is not adding them. See if that works for you. – Hazerd Oct 17 '16 at 08:35
  • Thanks a lot. Tried client.SetValue with a ToString() method for the object and it works better. I can achieve what I want with this now. – Satyajit Oct 17 '16 at 08:38

2 Answers2

1

It appears as though the client.Add() method converts the value to a string (even strings) and wraps them in quotes. The client.SetValue() method only accepts strings and does not wrap them in quotes.

One option would be to convert the value into a string yourself. Either via the common ToString() method, or another method to get the needed string from the object.

If the Add() method is necessary however. You could opt to check if the string is wrapped in quotes when you get it via GetValue() and if so, remove them.

Hazerd
  • 336
  • 1
  • 7
0

Redis converts string to JSON when saving, that's why it's wrapped in quotes.

So you have to treat this string as JSON object and parse it afterwards manually or using deserialization.

Nick Roz
  • 3,918
  • 2
  • 36
  • 57