Redis Storage Fabric

Source: Internet
Author: User
Tags hash redis
Base 2.8.7
Redis is a large dictionary that contains a lot of key-value pairs, and this dictionary supports a very rich set of value that can be used for strings, hash tables, lists, collections, and ordered sets, based on these types of rich value, extending powerful operations such as Hmset, Lpush, SADD, etc.

DictionaryA dictionary is the most basic data structure of Redis, and a dictionary is a db,redis that supports multiple db

The Redis dictionary usesHash TableThe method used for the collision problem is "Chain Address Method, which resolves the conflict by concatenating multiple nodes with the same hash value.
The problem with the "chain address method" is that when the collision is severe, the performance degradation is serious, for example: when there are n data, M slots, if m=1, then the entire hash table degenerate into a linked list, query complexity O (n)
to avoid hash collision attacks, Redis randomly hashes hash table seeds
The Redis scenario is"Double buffer", the normal process uses a buffer, when the collision is detected violently (judging by the current number of slots and the number of keys), assigning a larger buffer, and thengraduallyMigrate data from the old buffer to the new buffer.
The Redis dictionary structure is as follows:
[CPP]  View Plain  copy typedef struct dict {       dicttype  *type;        void *privdata;         dictht ht[2]; //Double buffer       int rehashidx;         int iterators;  } dict;      typedef  struct dictht {       dictentry **table; //hash Chain List        unsigned long size;       unsigned long  sizemask;       unsigned long used;  } dictht;      //Data nodes <K,V>   typedef struct dictentry {       void *key;       union {            void *val;            uint64_t u64;           int64_t s64;       } v;       struct dictEntry *next;   } dictentry;   Redisobject is a real storage of redis various types of structures, with the following content:
[CPP]View plain copy typedef struct REDISOBJECT {unsigned type:4;//logic type unsigned notused:2; /* Not used */unsigned encoding:4;        Physical storage type unsigned lru:22;       /* LRU time (relative to Server.lruclock) */int refcount;  void *ptr;   Specific data} RobJ; Where type is the type of logic supported by Redis, including:
[CPP]View Plain copy #define REDIS_STRING 0 #define REDIS_LIST 1 #define REDIS_SET 2 #define REDIS_ZSET 3 #define Redi S_hash 4 enconding is physical storage, a logical type can use different storage methods, including:
[CPP]View Plain copy #define REDIS_ENCODING_RAW 0/* RAW representation */#define REDIS_ENCODING_INT 1/* encoded a s integer */#define Redis_

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.