当前位置:网站首页>使用高斯Redis实现二级索引
使用高斯Redis实现二级索引
2022-07-07 17:38:00 【InfoQ】
一、背景




二、场景一:词典补全

2.1 基本方案
ZADD myindex 0 banana:1ZRANGEBYLEX myindex "[bit" "[bit\xff"2.2 与频率相关的词典补全
ZRANGEBYLEX myindex "[banana:" + LIMIT 0 1ZADD myindex 0 banana:1ZREM myindex 0 banana:1ZADD myindex 0 banana:2ZRANGEBYLEX myindex "[banana:" + LIMIT 0 10
1) "banana:123"
2) "banaooo:1"
3) "banned user:49"
4) "banning:89"ZREM myindex 0 banaooo:1ZREM myindex 0 banana:123
ZADD myindex 0 banana:122三、场景二:多维索引

3.1 数据编码


3.2 添加新元素
ZADD myindex 0 0001110000110010103.3 查询
def spacequery(x0,y0,x1,y1,exp)
bits=exp*2
x_start = x0/(2**exp)
x_end = x1/(2**exp)
y_start = y0/(2**exp)
y_end = y1/(2**exp)
(x_start..x_end).each{|x|
(y_start..y_end).each{|y|
x_range_start = x*(2**exp)
x_range_end = x_range_start | ((2**exp)-1)
y_range_start = y*(2**exp)
y_range_end = y_range_start | ((2**exp)-1)
puts "#{x},#{y} x from #{x_range_start} to #{x_range_end}, y from #{y_range_start} to #{y_range_end}"
# Turn it into interleaved form for ZRANGEBYLEX query.
# We assume we need 9 bits for each integer, so the final
# interleaved representation will be 18 bits.
xbin = x_range_start.to_s(2).rjust(9,'0')
ybin = y_range_start.to_s(2).rjust(9,'0')
s = xbin.split("").zip(ybin.split("")).flatten.compact.join("")
# Now that we have the start of the range, calculate the end
# by replacing the specified number of bits from 0 to 1.
e = s[0..-(bits+1)]+("1"*bits)
puts "ZRANGEBYLEX myindex [#{s} [#{e}"
}
}
end
spacequery(50,100,100,300,6)四、总结
附录
- 本文作者:华为云数据库GaussDB(for Redis)团队
- 杭州/西安/深圳简历投递:[email protected]
- 更多产品信息,欢迎访问官方博客:bbs.huaweicloud.com/blogs/248875
边栏推荐
- 吞吐量Throughout
- IP tools
- AI writes a poem
- PMP對工作有益嗎?怎麼選擇靠譜平臺讓備考更省心省力!!!
- 杰理之关于 TWS 配对方式配置【篇】
- 8 CAS
- String - string (Lua)
- Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
- 编译原理 实验一:词法分析器的自动实现(Lex词法分析)
- R language ggplot2 visualization: use the ggecdf function of ggpubr package to visualize the grouping experience cumulative density distribution function curve, and the linetype parameter to specify t
猜你喜欢

【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器

9 原子操作类之18罗汉增强

网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...

PV static creation and dynamic creation

论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》

干货分享|DevExpress v22.1原版帮助文档下载集合

超分辨率技术在实时音视频领域的研究与实践

CMD command enters MySQL times service name or command error (fool teaching)

The project manager's "eight interview questions" is equal to a meeting

Introduction to bit operation
随机推荐
Solve the error reporting problem of rosdep
Key points of anti reptile: identifying reptiles
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
2022如何评估与选择低代码开发平台?
微信公众号OAuth2.0授权登录并显示用户信息
Kirin Xin'an won the bid for the new generation dispatching project of State Grid!
How to buy bank financial products? Do you need a bank card?
Seize Jay Chou
[RT thread env tool installation]
Uvalive – 4621 CAV greed + analysis "suggestions collection"
转置卷积理论解释(输入输出大小分析)
Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
ant desgin 多选
How to open an account for stock speculation? Excuse me, is it safe to open a stock account by mobile phone?
实训九 网络服务的基本配置
PMP每日一练 | 考试不迷路-7.7
Solve the problem of remote rviz error reporting
杰理之关于 TWS 声道配置【篇】
Tp6 realize Commission ranking