redis_book/dict/README.md
2022-12-26 23:18:49 +08:00

31 lines
985 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 简介
字典是redis数据库最基本的结构其本质结构是hash用来存储键值对的一种数据结构Redis本身就是K-V数据库
整个数据库就是用字典存储的对于Redis数据库的增、删、改、查操作实际上都是对字典结构的操作。
## hash函数
对于字典来讲计算key的hash比较重要下面是Redis内核里面使用的计算的hash方法: [siphash](./siphash.md)
```c
static uint8_t dict_hash_function_seed[16];
uint64_t dictGenHashFunction(const void *key, size_t len) {
return siphash(key,len,dict_hash_function_seed);
}
```
`dictGenHashFunction`函数的主要作用是将任意长度的字符串计算siphash的值siphash是一个无符号整型数据。
在Redis当中将任意key转换为无符号整数类型当作hash结构的下表使用。
## hash冲突
Redis使用hash结构保存数据那么无法忽略的一个问题就是hash冲突。
# 基本操作
# 字典遍历