当前位置:网站首页>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 .
边栏推荐
- wsl常用命令
- 错误: 找不到符号
- Realization of the code for calculating the mean square error of GPS Height Fitting
- 初识C语言(上)
- 分支语句和循环语句
- isEmpty 和 isBlank 的用法区别
- [GNSS data processing] Helmert variance component estimation analysis and code implementation
- [algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
- 2年经验总结,告诉你如何做好项目管理
- RTKLIB: demo5 b34f.1 vs b33
猜你喜欢
随机推荐
初识C语言(上)
How to reduce the shutdown time of InnoDB database?
All in one 1405: sum and product of prime numbers
图书管理系统小练习
The earth revolves around the sun
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
国企秋招经验总结
编辑距离(多源BFS)
162. Find peak - binary search
wsl常用命令
121 distributed interview questions and answers
Detailed explanation of balanced binary tree is easy to understand
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组
TYUT太原理工大学2022“mao gai”必背
Comparative analysis of the execution efficiency of MySQL 5.7 statistical table records
一文搞定 UDP 和 TCP 高频面试题!
Record: I accidentally wrote a recursion next time
RTKLIB: demo5 b34f. 1 vs b33
10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
Heap sort [handwritten small root heap]

![[算法] 剑指offer2 golang 面试题1:整数除法](/img/e6/f17135207b3540ec58e5a9eed54220.png)








