当前位置:网站首页>使用高斯Redis实现二级索引
使用高斯Redis实现二级索引
2022-07-07 17:38:00 【InfoQ】
一、背景
二、场景一:词典补全
2.1 基本方案
ZADD myindex 0 banana:1
ZRANGEBYLEX myindex "[bit" "[bit\xff"
2.2 与频率相关的词典补全
ZRANGEBYLEX myindex "[banana:" + LIMIT 0 1
ZADD myindex 0 banana:1
ZREM myindex 0 banana:1
ZADD myindex 0 banana:2
ZRANGEBYLEX myindex "[banana:" + LIMIT 0 10
1) "banana:123"
2) "banaooo:1"
3) "banned user:49"
4) "banning:89"
ZREM myindex 0 banaooo:1
ZREM myindex 0 banana:123
ZADD myindex 0 banana:122
三、场景二:多维索引
3.1 数据编码
3.2 添加新元素
ZADD myindex 0 000111000011001010
3.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
边栏推荐
猜你喜欢
How to estimate the value of "not selling pens" Chenguang?
Download from MySQL official website: mysql8 for Linux X Version (Graphic explanation)
Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
【RT-Thread env 工具安装】
Research and practice of super-resolution technology in the field of real-time audio and video
el-upload上传组件的动态添加;el-upload动态上传文件;el-upload区分文件是哪个组件上传的。
J ü rgen schmidhub reviews the 25th anniversary of LSTM papers: long short term memory All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversar
最多可以参加的会议数目[贪心 + 优先队列]
关于ssh登录时卡顿30s左右的问题调试处理
PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
随机推荐
Mysql, sqlserver Oracle database connection mode
干货分享|DevExpress v22.1原版帮助文档下载集合
R language dplyr package select function, group_ The by function, filter function and do function obtain the third largest value of a specific numerical data column in a specified level in a specified
现在股票开户可以直接在网上开吗?安全吗。
PV static creation and dynamic creation
杰理之按键发起配对【篇】
What does "true" mean
Solve the problem of remote rviz error reporting
R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
一张图深入的理解FP/FN/Precision/Recall
Notes...
超分辨率技术在实时音视频领域的研究与实践
LeetCode1051(C#)
ASP. Net gymnasium integrated member management system source code, free sharing
Le PGR est - il utile au travail? Comment choisir une plate - forme fiable pour économiser le cœur et la main - d'œuvre lors de la préparation de l'examen!!!
Former richest man, addicted to farming
The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list
UCloud是基础云计算服务提供商
L1-027 rental (Lua)
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表