当前位置:网站首页>使用高斯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
边栏推荐
- Tips and tricks of image segmentation summarized from 39 Kabul competitions
- 转置卷积理论解释(输入输出大小分析)
- UCloud是基础云计算服务提供商
- R语言ggplot2可视化:使用ggpubr包的ggstripchart函数可视化分组点状条带图(dot strip plot)、设置position参数配置不同分组数据点的分离程度
- Key points of anti reptile: identifying reptiles
- how to prove compiler‘s correctness
- 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
- 怎么在手机上买股票开户 股票开户安全吗
- Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
- Jerry's headphones with the same channel are not allowed to pair [article]
猜你喜欢

Redis——基本使用(key、String、List、Set 、Zset 、Hash、Geo、Bitmap、Hyperloglog、事务 )

Kirin Xin'an cloud platform is newly upgraded!

小试牛刀之NunJucks模板引擎

8 CAS

Jürgen Schmidhuber回顾LSTM论文等发表25周年:Long Short-Term Memory. All computable metaverses. Hierarchical reinforcement learning (RL). Meta-RL. Abstractions in generative adversarial RL. Soccer learn

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

Nunjuks template engine

杰理之发起对耳配对、回连、开启可发现、可连接的轮循函数【篇】

AD域组策略管理

Netease Yunxin participated in the preparation of the standard "real time audio and video service (RTC) basic capability requirements and evaluation methods" issued by the Chinese Academy of Communica
随机推荐
Make this crmeb single merchant wechat mall system popular, so easy to use!
【牛客网刷题系列 之 Verilog进阶挑战】~ 多bit MUX同步器
9 原子操作类之18罗汉增强
炒股如何开户?请问一下手机开户股票开户安全吗?
Browse the purpose of point setting
[RT thread env tool installation]
PV static creation and dynamic creation
ant desgin 多选
R language ggplot2 visualization: use the ggviolin function of ggpubr package to visualize the violin diagram, set the palette parameter to customize the filling color of violin diagrams at different
Matplotlib drawing 3D graphics
Zhong Xuegao wants to remain innocent in the world
R语言ggplot2可视化:使用ggpubr包的ggdensity函数可视化分组密度图、使用stat_overlay_normal_density函数为每个分组的密度图叠加正太分布曲线
How to buy stocks on your mobile phone and open an account? Is it safe to open an account
Unable to link the remote redis server (solution 100%
转置卷积理论解释(输入输出大小分析)
R语言ggplot2可视化:使用ggpubr包的ggecdf函数可视化分组经验累积密度分布函数曲线、linetype参数指定不同分组曲线的线型
【Confluence】JVM内存调整
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
Nunjuks template engine
Tips and tricks of image segmentation summarized from 39 Kabul competitions