Awesome
<div align=center> <img src="imgs/tairzset_logo.jpg" width="500"/> </div>Introduction Chinese
TairZset is a data structure developed based on the redis module. Compared with the native zset data structure of redis, TairZset not only has the same rich data interface and high performance as the native zset, but also provides (arbitrary) multi-score sorting capabilities.
Features:
- Support multi-score(Limited to 255)sorting, and the accuracy of any dimension is not lost
- Incrby semantics is still supported under multi-score sorting
- The syntax is similar to redis zset
Sorting rules:
For multi-dimensional scores, the priority of the score on the left is greater than the score on the right. Take a three-dimensional score as an example: score1#score2#score3. When comparing, tairzset will compare score1 first, and only compare score2 when score1 is equal, otherwise it will Take the comparison result of score1 as the comparison result of the entire score. In the same way, score3 will be compared only when score2 is equal.
Application scenario:
- Sorting among gamers
- Anchor popularity ranking in live room
Quick start
127.0.0.1:6379> exzadd tairzsetkey 1.1 x 2.2 y
(integer) 2
127.0.0.1:6379> exzrange tairzsetkey 0 -1 withscores
1) "x"
2) "1.1000000000000001"
3) "y"
4) "2.2000000000000002"
127.0.0.1:6379> exzincrby tairzsetkey 2 x
"3.1000000000000001"
127.0.0.1:6379> exzrange tairzsetkey 0 -1 withscores
1) "y"
2) "2.2000000000000002"
3) "x"
4) "3.1000000000000001"
127.0.0.1:6379> exzadd tairzsetkey 3.3#3.3 z
(error) ERR score is not a valid format
127.0.0.1:6379> del tairzsetkey
(integer) 1
127.0.0.1:6379> exzadd tairzsetkey 1.1#3.3 x 2.2#2.2 y 3.3#1.1 z
(integer) 3
127.0.0.1:6379> exzrange tairzsetkey 0 -1 withscores
1) "x"
2) "1.1000000000000001#3.2999999999999998"
3) "y"
4) "2.2000000000000002#2.2000000000000002"
5) "z"
6) "3.2999999999999998#1.1000000000000001"
127.0.0.1:6379> exzincrby tairzsetkey 2 y
(error) ERR score is not a valid format
127.0.0.1:6379> exzincrby tairzsetkey 2#0 y
"4.2000000000000002#2.2000000000000002"
127.0.0.1:6379> exzrange tairzsetkey 0 -1 withscores
1) "x"
2) "1.1000000000000001#3.2999999999999998"
3) "z"
4) "3.2999999999999998#1.1000000000000001"
5) "y"
6) "4.2000000000000002#2.2000000000000002"
Docker
docker run -p 6379:6379 tairmodule/tairzset:latest
Build
mkdir build
cd build
cmake ../ && make -j
then the tairzset_module.so library file will be generated in the lib directory
./redis-server --loadmodule /path/to/tairzset_module.so
Test
- Modify the path in the tairzset.tcl file in the
tests
directory toset testmodule [file your_path/tairzset_module.so]
- Put tairzset.tcl or link it in redis/tests.
- run ./runtest --single tairzset
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
Applicable redis version
redis >= 5.0
Our modules
TairHash: A redis module, similar to redis hash, but you can set expire and version for the field
TairZset: A redis module, similar to redis zset, but you can set multiple scores for each member to support multi-dimensional sorting
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.