redis官方文档:https://redis.io/topics/data-...
redis支持二进制安全的字符串(Binary-safe strings),而且它的key也是二进制安全。
原文:
Redis keys
Redis keys are binary safe, this means that you can use any binary sequence as a key, from a string like "foo" to the content of a JPEG file. The empty string is also a valid key.
大意:
redis的key是二进制安全,也就是说你可以使用任何二进制序列作为一个key,"foo"是一个合法的key,一个JPEG图片文件也可以做一个合法的key。空的字符串也是一个合法的key。
那什么是二进制安全字符串呢?
参考:https://stackoverflow.com/que...
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.
翻译:redis字符串是一个字节序列。它是二进制安全的,也就是说它有一个已知的长度,这个长度不是由特殊的终止符决定。因此,你可以在一个字符串中存储最多512M的任意数据。
总结:
二进制安全字符串就是指可以包含任何的字符。
比如:有些语言,如C语言中,字符串结束标志是"\0"。如果有个字符串是:"hello\0world",c语言求字符串长度strlen,只会得到"hello"的长度(5),而php中,strlen会得到"hello\0world"的长度11。
php文档中也有二进制安全的说法,也是一样理解。
欢迎指错!