当前位置:网站首页>使用高斯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
边栏推荐
- Solve the problem of remote rviz error reporting
- how to prove compiler‘s correctness
- 转置卷积理论解释(输入输出大小分析)
- Training IX basic configuration of network services
- Is PMP beneficial to work? How to choose a reliable platform to make it easier to prepare for the exam!!!
- Empowering smart power construction | Kirin Xin'an high availability cluster management system to ensure the continuity of users' key businesses
- LeetCode1051(C#)
- 网易云信参与中国信通院《实时音视频服务(RTC)基础能力要求及评估方法》标准编制...
- L1-019 who falls first (Lua)
- Dynamic addition of El upload upload component; El upload dynamically uploads files; El upload distinguishes which component uploads the file.
猜你喜欢

Command mode - unity

位运算介绍

The strength index of specialized and new software development enterprises was released, and Kirin Xin'an was honored on the list

Automatic classification of defective photovoltaic module cells in electroluminescence images-论文阅读笔记

Research and practice of super-resolution technology in the field of real-time audio and video

5billion, another master fund was born in Fujian

关于ssh登录时卡顿30s左右的问题调试处理
Make this crmeb single merchant wechat mall system popular, so easy to use!

PMP每日一练 | 考试不迷路-7.7

Welcome to the markdown editor
随机推荐
Install mysql8 for Linux X ultra detailed graphic tutorial
Nunjuks template engine
论文解读(ValidUtil)《Rethinking the Setting of Semi-supervised Learning on Graphs》
[confluence] JVM memory adjustment
State mode - Unity (finite state machine)
强化学习-学习笔记8 | Q-learning
Tp6 realize Commission ranking
Time tools
【Confluence】JVM内存调整
杰理之测试盒配置声道【篇】
R language ggplot2 visualization: use the ggstripchart function of ggpubr package to visualize the dot strip plot, set the position parameter, and configure the separation degree of different grouped
PMP对工作有益吗?怎么选择靠谱平台让备考更省心省力!!!
String - string (Lua)
Key points of anti reptile: identifying reptiles
杰理之开机自动配对【篇】
How to estimate the value of "not selling pens" Chenguang?
炒股如何开户?请问一下手机开户股票开户安全吗?
R语言使用ggplot2函数可视化需要构建泊松回归模型的计数目标变量的直方图分布并分析构建泊松回归模型的可行性
How to buy bank financial products? Do you need a bank card?
Seize Jay Chou