Redis - Compressing strings with Zlib

Viewed 1224

I'm trying to compress strings saved in redis on client side, to optimize memory usage.

The process is the following (pseudo):

string = "This is a compression test"
buffer = zlib.deflate(string)
redis.set('key', buffer.toString('base64'))
compressed = redis.get('key')
buffer = new Buffer(string, "base64")
string = zlib.unzip(buffer).toString()

This works, but the buffer here is saved a string. And if i compare string length, the compressed string is 45, compared to the normal string length which is 27.

I guess i'm doing something wrong here, cause i can't see how this would reduce memory usage. Is there a way to save directly the buffer in redis?

EDIT

I found the way to directly save a buffer and to retrieve it as buffer. Still the serializedlength of the plain string is 27, the serializedlength of the buffer is 33. So this still doesn't convince me.

Can someone explain me?

0 Answers
Related