当前位置:网站首页>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 .
边栏推荐
- 162. Find peak - binary search
- [算法] 剑指offer2 golang 面试题4:只出现一次的数字
- 阿里云微服务(三)Sentinel开源流控熔断降级组件
- 错误: 找不到符号
- 系统设计学习(一)Design Pastebin.com (or Bit.ly)
- Fgui project packaging and Publishing & importing unity & the way to display the UI
- 分支语句和循环语句
- Iterable、Collection、List 的常见方法签名以及含义
- [algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
- 记录:动态Web项目servlet访问数据库404错误之解决
猜你喜欢
Code example of MATLAB reading GNSS observation value o file
TYUT太原理工大学2022“mao gai”必背
【GNSS数据处理】赫尔默特(helmert)方差分量估计解析及代码实现
一文搞定 UDP 和 TCP 高频面试题!
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
Wechat applet development experience
[algorithm] sword finger offer2 golang interview question 8: the shortest subarray with a sum greater than or equal to K
[GNSS data processing] Helmert variance component estimation analysis and code implementation
Dark chain lock (lca+ difference on tree)
3月15号 Go 1.18 正式版发布 了解最新特色以及使用方法
随机推荐
Fundamentals of UD decomposition of KF UD decomposition [1]
[GNSS] robust estimation (robust estimation) principle and program implementation
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
Itext 7 生成PDF总结
[GNSS data processing] Helmert variance component estimation analysis and code implementation
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
isEmpty 和 isBlank 的用法区别
[algorithm] sword finger offer2 golang interview question 13: sum of numbers of two-dimensional submatrix
4.30 dynamic memory allocation notes
Detailed explanation of balanced binary tree is easy to understand
TYUT太原理工大学往年数据库简述题
编辑距离(多源BFS)
Record: I accidentally wrote a recursion next time
系统设计学习(一)Design Pastebin.com (or Bit.ly)
Record: newinstance() obsolete replacement method
TYUT太原理工大学2022数据库大题之E-R图转关系模式
Dark chain lock (lca+ difference on tree)
Error: symbol not found
GNSS positioning accuracy index calculation
继承和多态(下)