I have a groupid and a clientid and the value is val. All are ints, the length of groupid and clientid can go up to 7 digits from a minimum of 5 digits, while the val can only be three digits.
I tried storing this data by following two methods:
- method 1: I am trying to store this data using
HSET, by using this logic,hashI create by concatenatinggroupidandclientidand then doing floor division by400, thekeyI am creating by concatenatinggroupidandclientidand then converting toint. Thehash-max-ziplist-entriesis 512 (hence the floor division by 400) andhash-max-ziplist-valueis 64. - method 2: I create a 64 bit int where
groupidis stored in 32 bit andclientidis also stored in 32 bit but left shifted.valis same, three digit int.
When I compare these two methods, method 2 takes less memory than method 1. I thought this should not be the case, as using hset is a way to optimise space (as indicated in this article). So I am presuming, I am doing something wrong in method 1.
For small dataset (roughly 100k pairs) I did see, method 1 taking less memory but when I attempt to store 75 million pairs, method 2 turns out to be better.