17

What is a binary safe string ? Is it just a string with length attached in the string itself ? Why are they called binary safe then ? Not sure that I should tag redis, but read this term while reading redis doc.

1
  • 1
    It means you could use the contents of an image, for example, as a key. You are not confined to letters and digits. Jun 5, 2017 at 21:10

4 Answers 4

16

A binary safe string is one that can consist of any characters (bytes).

For example, many programming languages use the 0x00 character as an end-of-string marker, so in that sense a binary safe string is one that can consist of these.

7

Redis string is a sequence of bytes. Strings in Redis are binary safe, meaning they have a known length not determined by any special terminating characters. Thus, you can store anything up to 512 megabytes in one string.

https://www.tutorialspoint.com/redis/redis_data_types.htm

2

Binary safe string does not make any assumption about its length or terminating character. For example, in Redis (since you have mentioned Redis in your question), syntax for a binary safe bulk string is "$str_len\r\nbinary_safe_string\r\n". Here, the length of the string is made part of the string representation. With this, you can save anything as a string, say a JPEG image. Refer to Redis documentation for more details.

2

The definition of "binary safe string" in Redis's documentation is this.

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.

Therefore, binary security is relative to the c language string ended with the character '\0'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.