Redis Dictionary data structure

Source: Internet
Author: User
Tags rehash

    • The dictionary node. Key/value structure.

typedef struct Dictentry {void *key;        Union {void *val;        uint64_t U64;        int64_t S64;    Double D;    } V; struct Dictentry *next;} Dictentry;


    • Dictionary table

typedef struct DICTHT {dictentry **table; unsigned long size;    Dictionary size unsigned long sizemask; unsigned long used;} dictht;




    • Dictionary

typedef struct DICT {Dicttype *type;    void *privdata; Dictht ht[2]; Rehash, from old to new long rehashidx; /* rehashing not in progress if rehashidx = = 1 */int iterators; /* Number of iterators currently running */} dict;



    • Iterators

put safe 1 to define the iterator as safe, i.e. add, The lookup or other operation is with the other iterator exclusive.

/* if safe is set to 1  this is a safe iterator, that means, you can call *  dictAdd, dictFind, and other functions against the dictionary  Even while * iterating. otherwise it is a non safe iterator,  and only dictnext ()  * should be called while iterating. */ Typedef struct dictiterator {    dict *d;    long  index;    int table, safe;    dictentry *entry,  *nextentry;    /* unsafe iterator fingerprint for misuse  detection. */    long long fingerprint;}  dictiterator; 


The method of using fingerprints when designing iterators (Long Long dictfingerprint (dict *d))

When you apply for an iterator, a hash value is calculated based on the address, size, and usage of the current dictionary. Each time an iterator is used, the fingerprint of the iterator is compared

This iterator is not available if it is different from the current dictionary's thumbprint.

On the rehash of the dictionary

A dictionary is essentially a hash table. The rehash strategy for Redis is to record the location of each rehash each time

The operation of the dictionary is judged whether the rehash operation is in progress. If it is rehash, it takes too long to avoid an operation

Defines the maximum number of buckets for a single operation


Redis Dictionary data structure

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.