Redis and escaping binary data
I'm having a hard time understanding how to use binary data types with redis. I want to use the command
set '{binary data}' 'Alex'
what if the binary data actually includes a quote character or / r / n? I know I can get away from the characters, but is there an official list of characters that I need to run?
source to share
There is no need to do anything special with the data itself. All Redis strings are binary.
Your problem is with the redis-cli (this is a very good redis client to familiarize yourself with Redis, but almost never what you want in production due to usage and performance issues).
Your problem also relates to general (bash / sh / other) terminal escaping. Here's a good explanation.
I suggest you use python for this or whatever language you are comfortable with.
Example:
import redis
cli=redis.Redis('localhost', 6379)
with open('data.txt','rb') as f:
for d in f:
t = d.partition('\t')
cli.set(t[0], t[2].rstrip())
#EOF
source to share
You can send command as array of massive strings in Redis, no need to escape characters or Base64 encoding. Since bulky strings start at the length of the data, Redis doesn't try to parse the data bytes and instead just goes to the end to check for the terminating CR / LF pair:
*3<crlf>
$3<crlf>SET<crlf>
${binary_key_length}<crlf>{binary_key_data}<crlf>
${binary_data_length}<crlf>{binary_data}<crlf>
source to share
Found the answer: Redis says it is binary safe strings
You need to use Base64 on binary data to get a binary safe string.
Java converts bytes to binary safe string
As for your problem, when trying to pipe your redis text commands to the cli, you probably want to step through the file and avoid single quotes.
source to share