migueldeicaza / redis-sharp

A C#/.NET binding for the Redis server.
150 stars 62 forks source link

Key-string invalid when containing spaces or curley brackets #1

Open MartinDevillers opened 14 years ago

MartinDevillers commented 14 years ago

(Just my 2cts when I used this awesome API)

Keys that contain spaces or curly brackets can lead to undesirable behavior.

By design, redis does not allow keys to contain spaces, as spaces are used to separate parameters. Thus, if the Key-string contains a space, the semantics of the subsequent call made to Redis by this API are changed. This can lead to some nasty behavior.

Curly brackets can lead to problems since at some point the string is passed through a String.Format in redis-sharp. The function mistakenly sees the curly brackets as a formatting placeholder, leading to exceptions or other undesirable behavior

migueldeicaza commented 14 years ago

So you think taht the code should validate that keys do not contain spaces or curly braces?

everyone would pay the price for that.

MartinDevillers commented 14 years ago

If you want to squeeze out that last bit of performance then such checks are indeed 'unnecessary' overhead.

A quick benchmark tells me that checking a list of 1 million elements for spaces and curly braces takes about 150ms, while it still takes 11 seconds to actually store the information in Redis. Encoding the whole list to base64 form takes 800ms (which is what I ended up doing for my thesis project)

Even if these checks shouldn't be in the main redis API, one can still imagine a 'safe' redis API that does the checks..

migueldeicaza commented 14 years ago

Thanks for measuring it.

If you send me a patch I'll integrate the changes. I do not really have a lot of spare time right now.