Redis knowledge (2)

Source: Internet
Author: User

1. Redis memory storage structure

This article is based on the Redis-v2.2.4 version for analysis.

1.1 overall Redis memory storage structure

Redis supports multiple key-value databases (tables) and uses RedisDb to represent a key-value database (table ). redisServer has a redisDb * db; member variable. During RedisServer initialization, A redisDb array is created based on the number of db in the configuration file. after the client connects, SELECT a reidsDb using the SELECT command. If this parameter is not specified, the default value is redisDb. after a client selects redisDb, subsequent operations are performed on this redisDb. the memory structure of redisDb is described in detail below.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/2102144292-0.jpg "style =" border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; text-align: center; background-color: # f3f3f3; padding: 4px 5px 5px; margin: 10px; "alt =" Image011710.jpg "/>

Redis memory storage structure

RedisDb definition:


Typedef struct redisDb {dict * dict;/* The keyspace for this DB */dict * expires;/* Timeout of keys with a timeout set */dict * blocking_keys; /* Keys with clients waiting for data (BLPOP) */dict * io_keys;/* Keys with clients waiting for vm I/O */dict * watched_keys; /* WATCHED keys for MULTI/exec cas */int id;} redisDb;


In redisDb, dict members are related to the actual stored data. dict is defined as follows:


Typedef struct dictEntry {void * key; void * val; struct dictEntry * next;} dictEntry; typedef struct dictType {unsigned int (* hashFunction) (const void * key ); void * (* keyDup) (void * privdata, const void * key); void * (* valDup) (void * privdata, const void * obj); int (* keyCompare) (void * privdata, const void * key1, const void * key2); void (* keyDestructor) (void * privdata, void * key); void (* valDestructor) (void * privdata, void * obj);} dictType;/* This is our hash table structure. every dictionary has two of this as we * implement incremental rehashing, for the old to the new table. */typedef struct dictht {dictEntry ** table; unsigned long size; unsigned long sizemask; unsigned long used;} dictht; typedef struct dict {dictType * type; void * privdata; dictht ht [2]; int rehashidx;/* rehashing not in progress if rehashidx =-1 */int iterators;/* number of iterators currently running */} dict;



This article is from the "ant nest" blog, please be sure to keep this source http://feihan21.blog.51cto.com/1364153/1300007

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.