File tree Expand file tree Collapse file tree 5 files changed +49
-2
lines changed Expand file tree Collapse file tree 5 files changed +49
-2
lines changed Original file line number Diff line number Diff line change @@ -193,6 +193,7 @@ JVM 这部分内容主要参考 [JVM 虚拟机规范-Java8 ](https://docs.oracle
193
193
194
194
- [ Redis 常见问题总结] ( docs/database/redis/redis-questions-01.md )
195
195
- [ 3种常用的缓存读写策略详解] ( docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md )
196
+ - [ Redis 5 种基本数据结构详解] ( ./docs/database/redis/redis-data-structures-01.md )
196
197
- [ Redis 内存碎片详解] ( ./docs/database/redis/redis-memory-fragmentation.md )
197
198
- [ Redis 集群详解] ( ./docs/database/redis/redis-cluster.md )
198
199
Original file line number Diff line number Diff line change @@ -264,6 +264,7 @@ export const sidebarConfig = defineSidebarConfig({
264
264
collapsable : true ,
265
265
children : [
266
266
"3-commonly-used-cache-read-and-write-strategies" ,
267
+ "redis-data-structures-01" ,
267
268
"redis-memory-fragmentation" ,
268
269
"redis-cluster" ,
269
270
] ,
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Redis 5 种基本数据结构详解
3
+ category : 数据库
4
+ tag :
5
+ - Redis
6
+ ---
7
+
1
8
你可以在 Redis 官网上找到 Redis 数据结构非常详细的介绍:[ Redis Data Structures] ( https://redis.com/redis-enterprise/data-structures/ ) 。未来随着 Redis 新版本的发布,可能会有新的数据结构出现,通过查阅 Redis 官网对应的介绍,你总能获取到最靠谱的信息。
2
9
3
10
## String(字符串)
@@ -269,7 +276,7 @@ Redis 中的 Set 类型是一种无序集合,集合中的元素没有先后顺
269
276
| SUNIONSTORE destination key1 key2 ... | 将给定所有集合的并集存储在 destination 中 |
270
277
| SDIFF key1 key2 ... | 获取给定所有集合的差集 |
271
278
| SDIFFSTORE destination key1 key2 ... | 将给定所有集合的差集存储在 destination 中 |
272
- | SPOP key | 随机移除并获取指定集合中一个或多个元素 |
279
+ | SPOP key count | 随机移除并获取指定集合中一个或多个元素 |
273
280
| SRANDMEMBER key count | 随机获取指定集合中指定数量的元素 |
274
281
275
282
更多 Redis Set 命令以及详细使用指南,请查看 Redis 官网对应的介绍:https://redis.io/commands/?group=set 。
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : Redis 3 种特殊数据结构详解
3
+ category : 数据库
4
+ tag :
5
+ - Redis
6
+ ---
7
+
1
8
### Bitmap
2
9
3
10
#### 介绍
Original file line number Diff line number Diff line change @@ -117,7 +117,21 @@ Redis 5.0 新增加的一个数据结构 `Stream` 可以用来做消息队列,
117
117
118
118
## Redis 数据结构
119
119
120
- ### Redis 常见的数据结构有哪些?
120
+ ### Redis 常用的数据结构有哪些?
121
+
122
+ - ** 5 种基础数据类型** :String(字符串)、List(列表)、Set(集合)、Hash(散列)、Zset(有序集合)。
123
+ - ** 3 种特殊数据类型** :HyperLogLogs(基数统计)、Bitmap (位存储)、Geospatial (地理位置)。
124
+
125
+ 关于 5 种基础数据类型的详细介绍请看这篇文章:[ Redis 5 种基本数据结构详解] ( ./redis-data-structures-01.md ) 。
126
+
127
+ ### String 的应用场景有哪些?
128
+
129
+ - 常规数据(比如 session、token、、序列化后的对象)的缓存;
130
+ - 计数比如用户单位时间的请求数(简单限流可以用到)、页面单位时间的访问数;
131
+ - 分布式锁(利用 ` SETNX key value ` 命令可以实现一个最简易的分布式锁);
132
+ - ......
133
+
134
+ 关于 String 的详细介绍请看这篇文章:[ Redis 5 种基本数据结构详解] ( ./redis-data-structures-01.md ) 。
121
135
122
136
### String 还是 Hash 存储对象数据更好呢?
123
137
@@ -135,6 +149,23 @@ Redis 5.0 新增加的一个数据结构 `Stream` 可以用来做消息队列,
135
149
136
150
由于购物车中的商品频繁修改和变动,这个时候 Hash 就非常适合了!
137
151
152
+ ### 使用 Redis 实现一个排行榜怎么做?
153
+
154
+ Redis 中有一个叫做 ` sorted set ` 的数据结构经常被用在各种排行榜的场景,比如直播间送礼物的排行榜、朋友圈的微信步数排行榜、王者荣耀中的段位排行榜、话题热度排行榜等等。
155
+
156
+ 相关的一些 Redis 命令: ` ZRANGE ` (从小到大排序) 、 ` ZREVRANGE ` (从大到小排序)、` ZREVRANK ` (指定元素排名)。
157
+
158
+ ![ ] ( https://img-blog.csdnimg.cn/2021060714195385.png )
159
+
160
+ [ 《Java 面试指北》] ( https://www.yuque.com/docs/share/f37fc804-bfe6-4b0d-b373-9c462188fec7 ) 的「技术面试题篇」就有一篇文章详细介绍如何使用 Sorted Set 来设计制作一个排行榜。
161
+
162
+ ![ ] ( https://guide-blog-images.oss-cn-shenzhen.aliyuncs.com/github/javaguide/database/redis/image-20220719071115140.png )
163
+
164
+ ### 使用 Set 实现抽奖系统需要用到什么命令?
165
+
166
+ - ` SPOP key count ` : 随机移除并获取指定集合中一个或多个元素,适合不允许重复中奖的场景。
167
+ - ` SRANDMEMBER key count ` : 随机获取指定集合中指定数量的元素,适合允许重复中奖的场景。
168
+
138
169
## Redis 线程模型
139
170
140
171
### Redis 单线程模型了解吗?
You can’t perform that action at this time.
0 commit comments