当前位置:网站首页>使用高斯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
边栏推荐
- tp6 实现佣金排行榜
- 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
- 杰理之开机自动配对【篇】
- Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
- how to prove compiler‘s correctness
- How to estimate the value of "not selling pens" Chenguang?
- R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
- ASP.NET幼儿园连锁管理系统源码
- Responsibility chain model - unity
- R语言ggplot2可视化:使用ggpubr包的ggqqplot函数可视化QQ图(Quantile-Quantile plot)
猜你喜欢
Redis master-slave and sentinel master-slave switchover are built step by step
5billion, another master fund was born in Fujian
Responsibility chain model - unity
How to share the same storage among multiple kubernetes clusters
State mode - Unity (finite state machine)
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
最多可以参加的会议数目[贪心 + 优先队列]
Command mode - unity
9 atomic operation class 18 Rohan enhancement
Business experience in virtual digital human
随机推荐
how to prove compiler‘s correctness
R语言ggplot2可视化:使用ggpubr包的ggviolin函数可视化小提琴图、设置palette参数自定义不同水平小提琴图的填充色、add参数在小提琴图添加箱图
让这个 CRMEB 单商户微信商城系统火起来,太好用了!
Zhong Xuegao wants to remain innocent in the world
Unable to link the remote redis server (solution 100%
Seize Jay Chou
L1-023 output gplt (Lua)
Specify the version of OpenCV non-standard installation
爬虫实战(七):爬王者英雄图片
AD域组策略管理
How to estimate the value of "not selling pens" Chenguang?
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
Visual Studio 插件之CodeMaid自动整理代码
L1-027 rental (Lua)
小试牛刀之NunJucks模板引擎
R语言fpc包的dbscan函数对数据进行密度聚类分析、查看所有样本的聚类标签、table函数计算聚类簇标签与实际标签构成的二维列联表
Navicat连接2002 - Can‘t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock‘解决
L1-028 judging prime number (Lua)
Mysql, sqlserver Oracle database connection mode
A pot of stew, a collection of common commands of NPM and yarn cnpm