Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis: acceptable characters for values

Tags:

redis

I am aware of the naming conventions for Redis keys (this is a great link here Naming Convention and Valid Characters for a Redis Key ) but what of the values? Will I have an issue if my values include characters such as &^*$@+{ ?

like image 349
Les Paul Avatar asked Feb 21 '26 14:02

Les Paul


2 Answers

From http://redis.io/topics/data-types:

Redis Strings are binary safe, this means that a Redis string can contain any kind of data, for instance a JPEG image or a serialized Ruby object. A String value can be at max 512 Megabytes in length.

So those chars you've specified will be fine, as will any other data.

like image 183
Ruan Avatar answered Feb 24 '26 15:02

Ruan


@Ruan is not exactly covering the whole story. I have looked close at that section of the Redis docs and it doesn't cover special characters.

For example, you will need to escape double quotes " with a preceding backslash \" in your key.

Also if you do have special characters in your key i.e, spaces, single or double quotes, you will need to wrap your whole key in double quotes.

The following keys are valid and you can use them to start understanding how special characters are handled.

The following allows spaces in your key.

set "users:100:John Doe" 1234

The following allows special characters by escaping them.

set "metadata:2:moniker\"@\"" 1234
like image 39
Eat at Joes Avatar answered Feb 24 '26 15:02

Eat at Joes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!