当前位置:网站首页>Introduction and use of redis
Introduction and use of redis
2022-07-06 13:08:00 【Geometer】
redis summary
redis It's a non relational database , The key value database deployed in the slave , Its value There are five types , Respectively string,set,hash,list,zset
STRING: You can store strings , Integer or floating point , You can operate on the whole string or strings in the string , When it is an integer or floating-point number , Self increase or self decrease operation can be carried out
LIST: Main storage list . Press or eject both ends , You can trim multiple elements , Keep only the elements in one range
SET : You can add, get, and remove individual elements , Calculate and hand in , and , Difference set , Get elements randomly from the collection
HASH: You can add, get, and remove individual elements , Check if the element exists , Get all key value pairs
ZSET: Add get delete element , Get the element according to the score range or member , Calculate the rank of a key
The underlying implementation of data structure
string:
struct sdshdr{
int len;// Length of occupied space
int free;// Length of remaining space
char buf[];// Data space
}
Compared to calling directly c The advantage of string is that it can directly save the length without traversal . In addition, it can also reduce the problem of buffer overflow , Because the remaining length will be checked before use .
list:
Double linked list , But more about it
typedef struct listNode{
struct listNode *prev;
struct listNode * next;
void * value;
}
hash:
typedef struct dictht {
// Hash table array
dictEntry **table;
// Hash table size
unsigned long size;
// Hash table size mask , Used to calculate index values
unsigned long sizemask;
// The number of existing nodes in the hash table
unsigned long used;
}
typeof struct dictEntry{
// key
void *key;
// value
// Different key values may correspond to different types ,
// Therefore use union To solve this problem
union{
void *val;
uint64_tu64;
int64_ts64;
}
struct dictEntry *next;
}
When hash When the conflict , Using zippers to resolve conflicts
zset:
The bottom layer is realized by jumping table , It can be used to replace binary balanced tree
Skip list (skiplist) Is an ordered data structure , It maintains multiple pointers to other nodes in each node , So as to achieve the purpose of quickly finding access nodes . The jump table is a kind of randomized data , A jump table stores elements in a hierarchical linked list in an orderly manner , Efficiency is as good as the balance tree —— lookup 、 Delete 、 Add and other operations can be done in O(logn) Finish... In the expected time .
// Specific implementation of node
typedef struct zskiplistNode{
// layer
struct zskiplistLevel{
// Forward pointer
struct zskiplistNode *forward;
// span
unsigned int span;
} level[];
// Back pointer
struct zskiplistNode *backward;
// The score is
double score;
// member object
robj *obj;
}
typedef struct zskiplist {
// Header node and footer node
structz skiplistNode *header,*tail;
// The number of nodes in the table
unsigned long length;
// The number of layers of the node with the largest number of layers in the table
int level;
}zskiplist;
Friends who don't know about it can see the following post
Skip List– Jump watch ( There is no one of the most detailed jump table articles in the whole network )
set:
typedef struct intset{
// Encoding mode int16_t、int32_t、int64_t
uint32_t enconding;
// Number of elements contained in the collection
uint32_t length;
// Array to hold elements
int8_t contents[];
}
intset yes Redis One of the memory data structures , And before sds、 skiplist、dict、adlist
And other general data , It is Redis Peculiar , Used to implement Redis Of Set structure ( When the element is small and of numeric type ), Its characteristics are :Element type can only be numeric . There are three types of elements :int16_t、int32_t、int64_t. The elements are in order , Do not repeat .
intset and sds equally , Memory is continuous , It's like an array .
边栏推荐
- [algorithm] sword finger offer2 golang interview question 3: the number of 1 in the binary form of the first n numbers
- 一文搞定 UDP 和 TCP 高频面试题!
- Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
- 十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
- 系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- Compile GDAL source code with nmake (win10, vs2022)
- C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
- 国企秋招经验总结
- TYUT太原理工大学2022软工导论考试题型大纲
猜你喜欢
[algorithm] sword finger offer2 golang interview question 5: maximum product of word length
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
国企秋招经验总结
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
Edit distance (multi-source BFS)
Novatel board oem617d configuration step record
抽象类和接口
Basic DOS commands
[algorithm] sword finger offer2 golang interview question 10: subarray with sum K
随机推荐
TYUT太原理工大学2022软工导论简答题
First acquaintance with C language (Part 1)
TYUT太原理工大学往年数据库简述题
Employment of cashier [differential constraint]
《软件测试》习题答案:第一章
RTKLIB: demo5 b34f.1 vs b33
[算法] 劍指offer2 golang 面試題2:二進制加法
Record: newinstance() obsolete replacement method
[Yu Yue education] guide business reference materials of Wuxi Vocational and Technical College of Commerce
[GNSS data processing] Helmert variance component estimation analysis and code implementation
MySQL backup -- common errors in xtrabackup backup
Tyut Taiyuan University of technology 2022 introduction to software engineering examination question outline
初识C语言(下)
如何保障 MySQL 和 Redis 的数据一致性?
十分钟彻底掌握缓存击穿、缓存穿透、缓存雪崩
记录:newInstance()过时的代替方法
图书管理系统小练习
继承和多态(上)
2022 National Games RE1 baby_ tree
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal