Search code examples
redisbooksleeve

What is the proper way to retrieve string key/values from Redis using BookSleeve


I'm new to BookSleeve and it seems that the API has changed even when compared to what is documented in the website.

AS it is noted in the website:

"Note the API may change a little going to 1.0, but is stable enough to drive Stack Exchange.."

So it seems that the documentation is not current anymore.

Anyway, the question is, what is the correct way to retrieve keys that you have previously stored. I am using the 'String' API.

Is the following correct assumming an opened connection?:

var result = redisConnection.Strings.Get(0, "myKey");
byte[] buffer = redisConnection.Wait(result);
string str = System.Text.Encoding.Unicode.GetString(buffer, 0, buffer.Length);

Solution

  • You can simply use connection.Strings.GetString. But if you do use System.Text.Encoding, then use System.Text.Encoding.UTF8. Redis strings are UTF8.