- When two keys have the same value, there are two key names and two key values stored in Redis.
A long time ago there was a post to this group by a Redis developer suggesting that, for values that are integer numbers (0, 1, 2, etc.) keys containing the same value would "share" the value. I.e., after 'SET KEYA 1', 'SET KEYB 1', Redis would store the two key names "KEYA" and "KEYB" but only one value "1", and both key names would point to the shared value. This was done as a way to economize on memory. However, it was only true for that one particular data type, and it's not a very important optimization because simple integer values are a small part of Redis use cases. Also, as soon as one of the keys is changed (incremented, decremented, or a new value written), Redis must store a separate value for updated key, and now the optimization disappears.
Redis has seen major feature changes in the years since that post was made, so I would not be surprised if that small memory optimization is no longer present.