I'm trying to create a script to decode data from redis. I can make this a node script but I just wanted it to be as simple as possible.

Here's what I got so far.

redis-cli GET "d1g8y" | xargs -i node -e "require('zlib').gunzip(Buffer.from('{}', 'base64'), function(err, string) { console.log(string.toString()); })"

And it doesn't work. How do I get the result from this command redis-cli GET "d1g8y" and put that into this script Buffer.from('$VARIABLE_FROM_PREVIOUS_COMMAND', 'base64')

This is how I compressed the data

const zlib = require('zlib');

const zipAsync = Promise.promisify(zlib.gzip, {context: zlib});
return zipAsync(Buffer.from(value)).then(console.log);



Why use node at all? Kind of deer hunting with a howitzer, no?

redis-cli GET "d1g8y" | zcat | base64 --decode

zcat will transmogrify gzipped data into plaintext, which in your case happens to be a base64-encoded string, so we simply pipe that into the decoder.

|improve this answer|||||
  • I didn't know this command at all. Thanks. But I got this error when trying to do this. echo 'H4sIAAAAAAAAA5WOsQ2AMAwEV0GumYAaBgnYSiyCjRxTIMTuOCPw5Z10+gdWxRsmaHqQF5YMIxRKGIjFyah5wKGjykJhkfaQVf8tGkhtMz6dVSKTLi9qUZqTp2GRHHWyfuD9ALqyV6uVAAAA' | zcat | base64 --decode – toy Apr 3 '17 at 15:20
  • I use gzip to compress the data. I'll edit the question to show how I compress the data – toy Apr 3 '17 at 15:21
  • 1
    In your echo test, you're not sending gzipped data to zcat, so it fails on you. To emulate the unzipping-into-decode, use echo | gzip | zcat | base64. Or, to emulate the full stack, plaintext to encode to compress to uncompress to decode to plaintest: echo "asdf" | base64 | gzip | zcat | base64 --decode (which is probably the most convoluted echo I've done in a long, long time (: ). – DopeGhoti Apr 3 '17 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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