csredis icon indicating copy to clipboard operation
csredis copied to clipboard

Troubles, when key contains special escape

Open Bolg08 opened this issue 5 years ago • 1 comments

I have a method, which add data to HSET The key of рash is the path as Path.Combine

var baseAddress =Path.Combine(address,obj.GetType().FullName);
var pattern = baseAddress + "*";
var keys = await _client.KeysAsync(pattern);
var properties = obj.GetProperties();
await _client.HSetAsync(Path.Combine(baseAddress,keys.Length.ToString()),
key,value);

In redis, the key is written including special escape as `"a\\c" (for example)

When i try to get a list of keys using KeysAsync(pattern) i get an empty list If in the search pattern i replace all special escape (example: "a\\c" to "a\\\\c" ) i get true result

Help solve the problem?

Why in KeysAsync and HSetAsync keys are interpreted differently?

Bolg08 avatar Oct 20 '20 11:10 Bolg08

I may be wrong but I believe this is intentional. Writing keys are written as sent to Redis but when reading you have to escape the special characters. If you don't want this functionality you can always scrub special characters from your keys before writing. That's what I do.

On Tue, Oct 20, 2020 at 7:21 AM Bolg08 [email protected] wrote:

I have a method, which add data to HSET The key of рash is the path as Path.Combine

var baseAddress =Path.Combine(address,obj.GetType().FullName);

var pattern = baseAddress + "*";

var keys = await _client.KeysAsync(pattern);

var properties = obj.GetProperties();

await _client.HSetAsync(Path.Combine(baseAddress,keys.Length.ToString()),

key,value);

In redis, the key is written including special escape as `"a\c" (for example)

When i try to get a list of keys using KeysAsync(pattern) i get an empty list If in the search pattern i replace all special escape (example: "a\c" to "a\\c" ) i get true result

Help solve the problem?

Why in KeysAsync and HSetAsync keys are interpreted differently?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ctstone/csredis/issues/65, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABPOK4RGNH3IGGWYTH4EIWLSLVXCXANCNFSM4SYFCJRQ .

OmikronTheta avatar Oct 21 '20 13:10 OmikronTheta