Skip to main content
$

Bulk String

RESP2

prefix: $  ·  client type: String / bytes / Optional[str]

Bulk strings are binary-safe strings with an explicit length prefix. Format: $<length>\r\n<bytes>\r\n. The length prefix allows the string to contain any bytes including \r and \n. $-1\r\n represents a null bulk string. Used for most string data returned by Redis: GET values, HGET field values, LRANGE elements.

Details

Bulk strings are the workhorse of RESP2. The format is $<length>\r\n<data>\r\n where length is the byte count of data (not character count).

Null bulk string: $-1\r\n represents a missing value (e.g., GET on a non-existent key). Clients should return nil/null/None.

Empty bulk string: $0\r\n\r\n is an empty string, distinct from null.

Binary safe: the length prefix means no special escaping is needed. A bulk string can contain \x00 bytes, newlines, or any other byte sequence.

In RESP3: bulk strings remain. The verbatim string (=) is a new type that adds a format hint (txt: or mkd:) for strings meant to be displayed directly to humans.

Max size: Redis allows bulk strings up to 512 MB (proto-max-bulk-len configuration).

Wire encoding

Wire bytes (CRLF shown as \\r\\n)
$11\r\nhello world\r\n
$0\r\n\r\n         # empty string
$-1\r\n             # null (GET non-existent key)

Type information

Prefix byte$
VersionRESP2
Client typeString / bytes / Optional[str]
SpecificationRESP3 specification (GitHub) →

Redis commands returning this type

GETHGETLINDEXGETRANGESUBSTR

See Also