Created
April 28, 2024 03:42
-
-
Save deepinder10/dfaf6ec9781abd045162f68939deb0c6 to your computer and use it in GitHub Desktop.
Redis compression in NodeJS with LZ4 and Snappy
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
const Redis = require('ioredis'); | |
const lz4 = require('lz4-napi'); | |
const snappy = require('snappy'); | |
async function compress() { | |
const compressedData = await lz4.compress(JSON.stringify(json)); | |
// const compressedData = await snappy.compress(JSON.stringify(sampleData)); | |
await client.set(key, compressedData); | |
} | |
async function decompress() { | |
const data = await client.getBuffer(key); | |
const jsonData = await lz4.uncompress(data); | |
// const jsonData = await snappy.uncompress(data); | |
const parsedData = JSON.parse(jsonData); | |
// const parsedData = jsonData.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment