Bottom: string

Bottom: string

redis string is a SDS (simple dynamic string), similar to the ArrayList, there are three fields (size, capacity, flag bit) and one string, the string length of the allocated array and may be different.

Expansion

If append operation array expansion will be carried out, if the string is a lot of memory allocation and copying costs will be enormous. redis string no longer than a predetermined 512M, arrays, and allocating the same as the actual length of the string create, append does not occur because in most cases. When the string is less than 1M, expansion doubled after a time greater than 1M plus 1M.

Storage form: emb and raw

Emb string stored using very short length, the length of the string than 44 bytes (header + the actual object string of 64 bytes) stored in a raw form. It redisobject presence embstr SDS object header and an object a continuous space, and the object header and raw strings are not together, and if the object header string together more than 64 bytes, it is considered large Redis string (this number and memory For integer multiple dispensing), this time the real length of the string it is only 44 bytes (16 bytes representing object header, length, volume and flag string occupy 3 bytes, 64-16-3 = 44) .

Object type head which data is stored, a storage form, the LRU, the reference pointer points to the data and count.

Optimization of field

redis ultimate memory optimization is, when a character string is short, and the actual length of array length with byte fields to save space and short type.

Guess you like

Origin www.cnblogs.com/shizhuoping/p/11521158.html