Skip to content

Instantly share code, notes, and snippets.

@jamesmoriarty
Created October 26, 2017 04:46
Show Gist options
  • Save jamesmoriarty/35b14c139e63424a8fa87043ff0e2c95 to your computer and use it in GitHub Desktop.
Save jamesmoriarty/35b14c139e63424a8fa87043ff0e2c95 to your computer and use it in GitHub Desktop.
ioredis fragment compression
var Redis = require('ioredis');
const zlib = require('zlib');
Redis.Command.setArgumentTransformer('set', (args) => {
const value = args[1];
switch (typeof value){
case 'string':
args[1] = zlib.gzipSync(value).toString('base64');
return args;
default:
return args;
};
});
Redis.Command.setReplyTransformer('get', (result) => {
switch (typeof result){
case 'string':
return zlib.gunzipSync(new Buffer(result, 'base64')).toString();
default:
return result;
};
});
var redis = new Redis();
redis.set('key', '1'.repeat(1000), function(error, result){
redis.get('key', function(error, result){
throw result;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment