当前位置:网站首页>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 .
边栏推荐
- Application architecture of large live broadcast platform
- [algorithm] sword finger offer2 golang interview question 1: integer division
- Record: newinstance() obsolete replacement method
- Experience summary of autumn recruitment of state-owned enterprises
- [algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
- 最短Hamilton路径 (状压DP)
- 面试必备:聊聊分布式锁的多种实现!
- [算法] 剑指offer2 golang 面试题4:只出现一次的数字
- The earth revolves around the sun
- WSL common commands
猜你喜欢

一文搞定 UDP 和 TCP 高频面试题!
![[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组](/img/65/fc3fb5a217a3b44f506b695af53e2c.png)
[算法] 剑指offer2 golang 面试题9:乘积小于k的子数组

TYUT太原理工大学2022数据库大题之数据库操作

Several high-frequency JVM interview questions

Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
![[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数](/img/64/0f352232359c7d44f12b20a64c7bb4.png)
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数

121道分布式面试题和答案
![[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once](/img/f7/23ffc81ec8e9161c15d863c1a67916.png)
[algorithm] sword finger offer2 golang interview question 4: numbers that appear only once
![[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积](/img/e0/cea31070d6365eb57013cdead4a175.png)
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积

Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
随机推荐
GNSS positioning accuracy index calculation
Itext 7 生成PDF总结
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
最短Hamilton路径 (状压DP)
微信小程序开发心得
Edit distance (multi-source BFS)
Compile GDAL source code with nmake (win10, vs2022)
[algorithm] sword finger offer2 golang interview question 6: sum of two numbers in the sorting array
rtklib单点定位spp使用抗差估计遇到的问题及解决
All in one 1405: sum and product of prime numbers
[untitled]
TYUT太原理工大学2022软工导论简答题
[算法] 剑指offer2 golang 面试题3:前n个数字二进制形式中1的个数
TYUT太原理工大学往年数据库简述题
图书管理系统小练习
一文搞定 UDP 和 TCP 高频面试题!
[算法] 剑指offer2 golang 面试题5:单词长度的最大乘积
国企秋招经验总结
PRIDE-PPPAR源码解析
C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
