

[](https://github.com/alibaba/TairHash/actions/workflows/cmake.yml)
[](https://github.com/alibaba/TairHash/actions/workflows/ci.yml)
[](https://github.com/alibaba/TairHash/actions/workflows/docker-image.yml)
[](https://codecov.io/gh/chenyang8094/TairHash)
<div align=center>
<img src="imgs/tairhash_logo.jpg" width="500"/>
</div>
## Introduction [中文说明](README-CN.md)
TairHash is a hash data structure developed based on the redis module. TairHash not only has the same rich data interface and high performance as the native hash, but also can set the expiration and version for the field. TairHash provides an active expiration mechanism, even if the field is not accessed after expiration, it can be actively deleted to release the memory.
### The main features:
- Supports all redis hash commands
- Supports setting expiration and version for field
- Support efficient active expiration (SCAN mode, SORT mode and SLAB mode) and passivity expiration for field
- Support field expired event notification (based on pubsub)
## Active expiration
### SCAN_MODE(default):
- Do not sort TairHash globally (Smaller memory overhead)
- Each TairHash will still use a sort index to sort the fields internally (For expiration efficiency)
- The built-in timer will periodically use the SCAN command to find the TairHash that contains the expired field, and then check the sort index inside the TairHash to eliminate the field
- All keys and fields in the sorting index are pointer references, no memory copy, no memory expansion problem
**Supported redis version**: redis >= 5.0
**Advantages**: can run in the low version of redis (redis >= 5.0)
**Disadvantages**: low efficiency of expire elimination (compared with SORT mode and SLAB mode)
**Usage**: cmake with default option, and recompile
### SORT_MODE:
- Use a two-level sort index, the first level sorts the main key of tairhash, and the second level sorts the fields inside each tairhash
- The first-level uses the smallest ttl in the second-level for sorting, so the main key is globally ordered
- The built-in timer will periodically scan the first-level index to find out a key that has expired, and then check the secondary index of these keys to eliminate the expired fields. This is the active expire
- All keys and fields in the sorting index are pointer references, no memory copy, no memory expansion problem
**Supported redis version**: redis >= 7.0
**Advantages**: higher efficiency of expire elimination
**Disadvantages**: More memory consumption
**Usag**e: cmake with `-DSORT_MODE=yes` option, and recompile
### SLAB_MODE:
- Slab mode is a low memory usage (compared with SORT mode), cache-friendly, high-performance expiration algorithm
- Like SORT mode, keys are globally sorted to ensure that keys that need to be expired can be found faster. Unlike SORT mode, SLAB does not sort the fields inside the key, which saves memory overhead.
- The SLAB expiration algorithm uses SIMD instructions (when supported by the hardware) to speed up the search for expired fields
**Supported redis version**: redis >= 7.0
**Advantages**: Efficient elimination, low memory consumption, and fast access bring new ideas to expiration algorithms
**Disadvantages**: More memory consumption
**Usage**: cmake with `-DSLAB_MODE=yes` option, and recompile
## Passivity expiration
- Every time you read or write a field, it will also trigger the expiration of the field itself
- Every time you write a field, tairhash also checks whether other fields (may belong to other keys) are expired (currently up to 3 at a time), because fields are sorted by TTL, so this check will be very efficient (Note: SLAB_MODE does not support this feature)
## Event notification
tairhash will send an event notification when the field expires (triggered by active or passive expiration). The notification is sent in pubsub mode. The format of the channel is: `tairhash@<db>@<key>__:<event>` , currently only supports expired event type, so
The channel is: `tairhash@<db>@<key>__:expired`, and the message content is the expired field.
## Quick Start
```go
127.0.0.1:6379> EXHSET k f v ex 10
(integer) 1
127.0.0.1:6379> EXHGET k f
"v"
127.0.0.1:6379> EXISTS k
(integer) 1
127.0.0.1:6379> debug sleep 10
OK
(10.00s)
127.0.0.1:6379> EXISTS k
(integer) 0
127.0.0.1:6379> EXHGET k f
(nil)
127.0.0.1:6379> EXHSET k f v px 10000
(integer) 1
127.0.0.1:6379> EXHGET k f
"v"
127.0.0.1:6379> EXISTS k
(integer) 1
127.0.0.1:6379> debug sleep 10
OK
(10.00s)
127.0.0.1:6379> EXISTS k
(integer) 0
127.0.0.1:6379> EXHGET k f
(nil)
127.0.0.1:6379> EXHSET k f v VER 1
(integer) 1
127.0.0.1:6379> EXHSET k f v VER 1
(integer) 0
127.0.0.1:6379> EXHSET k f v VER 1
(error) ERR update version is stale
127.0.0.1:6379> EXHSET k f v ABS 1
(integer) 0
127.0.0.1:6379> EXHSET k f v ABS 2
(integer) 0
127.0.0.1:6379> EXHVER k f
(integer) 2
```
## Docker
```
docker run -p 6379:6379 tairmodule/tairhash:latest
```
## BUILD
```
mkdir build
cd build
cmake ../ && make -j
```
then the tairhash_module.so library file will be generated in the lib directory
```
./redis-server --loadmodule /path/to/tairhash_module.so
```
## TEST
1. Modify the path in the tairhash.tcl file in the `tests` directory to `set testmodule [file your_path/tairhash_module.so]`
2. Add the path of the tairhash.tcl file in the `tests` directory to the all_tests of redis test_helper.tcl
3. run ./runtest --single tairhash
## Client
| language | GitHub |
|----------|---|
| Java |https://github.com/alibaba/alibabacloud-tairjedis-sdk|
| Python |https://github.com/alibaba/tair-py|
| Go |https://github.com/alibaba/tair-go|
| .Net |https://github.com/alibaba/AlibabaCloud.TairSDK|
## API
[Reference](CMDDOC.md)
### Our modules
[TairHash](https://github.com/alibaba/TairHash): A redis module, similar to redis hash, but you can set expire and version for the field
[TairZset](https://github.com/alibaba/TairZset): A redis module, similar to redis zset, but you can set multiple scores for each member to support multi-dimensional sorting
[TairString](https://github.com/alibaba/TairString): A redis module, similar to redis string, but you can set expire and version for the value. It also provides many very useful commands, such as cas/cad, etc.
没有合适的资源?快使用搜索试试~ 我知道了~
一个redis模块,类似于redis hash,但是可以为字段设置过期时间和版本 .zip

共53个文件
h:12个
c:12个
md:8个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 101 浏览量
2024-12-03
12:41:12
上传
评论
收藏 829KB ZIP 举报
温馨提示
介绍 中文说明 TairHash 是基于 redis 模块开发的哈希数据结构。TairHash 不仅具有与原生哈希一样丰富的数据接口和高性能,还可以为字段设置过期时间和版本。TairHash 提供了主动过期机制,即使字段过期后没有被访问,也可以主动删除,释放内存。主要特点支持所有 redis hash 命令支持设置字段的过期时间和版本支持高效的字段主动过期(SCAN模式、SORT模式、SLAB模式)和被动过期支持字段过期事件通知(基于pubsub)主动到期扫描模式(默认)不对 TairHash 进行全局排序(较小的内存开销)每个 TairHash 仍将使用排序索引对字段进行内部排序(为了提高过期效率)内置定时器会定期使用 SCAN 命令查找包含过期字段的 TairHash,然后检查 TairHash 内部的排序索引,剔除该字段排序索引中所有key和字段都是指针引用,无内存拷贝,无内存扩展问题支持的redis版本redis >= 5.0优点可以运行在低版本的redis上(redis >= 5.0)缺点过期淘汰效率较低(与SOR
资源推荐
资源详情
资源评论






























收起资源包目录





























































共 53 条
- 1
资源评论


徐浪老师
- 粉丝: 9536
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 微信商城类小程序.zip
- 基于SLAM的规划算法仿真与复现项目_通过Python实现SLAM技术结合激光雷达数据构建环境地图并仿真多种路径规划算法如A和RRT的完整流程_用于机器人自主导航算法的研究教学和.zip
- HiApp 微信小程序版.zip
- 微信小程序仿微信, QQ 向左滑动删除操作。.zip
- matlab仿真模拟和GS算法实现光学相位恢复与波前重建_基于Gerchberg-Saxton迭代算法的光学相位恢复仿真系统_用于中国科学技术大学光学课程作业中的相位恢复与计算全息.zip
- 一个让 THREE 平台化的项目,目前已适配微信,淘宝,头条小程序,微信小游戏.zip
- 微信小程序-人脸检测.zip
- 微信小程序demo咯.zip
- disksim-FTL_一个基于磁盘模拟器的闪存转换层仿真项目_模拟NAND闪存存储设备的行为与性能_实现地址映射垃圾回收磨损均衡等关键算法_支持多种FTL策略如页映射块映射.zip
- 拼车微信小程序源码.zip
- 微信小程序高仿vivo商城.zip
- 运维密码微信小程序.zip
- mpvue构建微信小程序.zip
- 微信小程序+微信管理后台+微信用户前台.zip
- 微信小程序---左滑删除.zip
- 电影推荐 - 微信小程序.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
