Created
October 26, 2017 04:46
-
-
Save jamesmoriarty/35b14c139e63424a8fa87043ff0e2c95 to your computer and use it in GitHub Desktop.
ioredis fragment compression
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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