When a set of elements contains only integer values, and the small number of elements of the collection, Redis
use the set of integers (intset)
to store the set of elements.
intset
It is a compact array of structures, while supporting 16
bit, 32
bit and 64
bit integer.
structure
IntSet struct <T> { Int32 encoding; // encoding int32 length; // set the number of elements contained int <T> contents []; // save element integer array } intset;
-
contents
An array is set to achieve the underlying integer, each item sorted in ascending order in the array size value, and does not contain duplicate entries
upgrade
When adding a new element into the set of integers, if a new type of element than the set of integers conventional types of all elements to be long, integers need to upgrade the size of the underlying array extension, and then add
Upgrade strategy mainly in the following two benefits:
-
Enhance the flexibility of the set of integers
-
Note: the set of integers does not support downgrading operation, once the upgrade, code will remain after the upgrade status