mirror of
https://github.com/Snailclimb/JavaGuide
synced 2025-06-16 18:10:13 +08:00
[docs update]redis数据结构面试题完善
This commit is contained in:
parent
968d6bc83b
commit
e7b6ee630c
@ -193,6 +193,7 @@ JVM 这部分内容主要参考 [JVM 虚拟机规范-Java8 ](https://docs.oracle
|
|||||||
|
|
||||||
- [Redis 常见问题总结](docs/database/redis/redis-questions-01.md)
|
- [Redis 常见问题总结](docs/database/redis/redis-questions-01.md)
|
||||||
- [3种常用的缓存读写策略详解](docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md)
|
- [3种常用的缓存读写策略详解](docs/database/redis/3-commonly-used-cache-read-and-write-strategies.md)
|
||||||
|
- [Redis 5 种基本数据结构详解](./docs/database/redis/redis-data-structures-01.md)
|
||||||
- [Redis 内存碎片详解](./docs/database/redis/redis-memory-fragmentation.md)
|
- [Redis 内存碎片详解](./docs/database/redis/redis-memory-fragmentation.md)
|
||||||
- [Redis 集群详解](./docs/database/redis/redis-cluster.md)
|
- [Redis 集群详解](./docs/database/redis/redis-cluster.md)
|
||||||
|
|
||||||
|
@ -264,6 +264,7 @@ export const sidebarConfig = defineSidebarConfig({
|
|||||||
collapsable: true,
|
collapsable: true,
|
||||||
children: [
|
children: [
|
||||||
"3-commonly-used-cache-read-and-write-strategies",
|
"3-commonly-used-cache-read-and-write-strategies",
|
||||||
|
"redis-data-structures-01",
|
||||||
"redis-memory-fragmentation",
|
"redis-memory-fragmentation",
|
||||||
"redis-cluster",
|
"redis-cluster",
|
||||||
],
|
],
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: Redis 5 种基本数据结构详解
|
||||||
|
category: 数据库
|
||||||
|
tag:
|
||||||
|
- Redis
|
||||||
|
---
|
||||||
|
|
||||||
你可以在 Redis 官网上找到 Redis 数据结构非常详细的介绍:[Redis Data Structures](https://redis.com/redis-enterprise/data-structures/) 。未来随着 Redis 新版本的发布,可能会有新的数据结构出现,通过查阅 Redis 官网对应的介绍,你总能获取到最靠谱的信息。
|
你可以在 Redis 官网上找到 Redis 数据结构非常详细的介绍:[Redis Data Structures](https://redis.com/redis-enterprise/data-structures/) 。未来随着 Redis 新版本的发布,可能会有新的数据结构出现,通过查阅 Redis 官网对应的介绍,你总能获取到最靠谱的信息。
|
||||||
|
|
||||||
## String(字符串)
|
## String(字符串)
|
||||||
@ -269,7 +276,7 @@ Redis 中的 Set 类型是一种无序集合,集合中的元素没有先后顺
|
|||||||
| SUNIONSTORE destination key1 key2 ... | 将给定所有集合的并集存储在 destination 中 |
|
| SUNIONSTORE destination key1 key2 ... | 将给定所有集合的并集存储在 destination 中 |
|
||||||
| SDIFF key1 key2 ... | 获取给定所有集合的差集 |
|
| SDIFF key1 key2 ... | 获取给定所有集合的差集 |
|
||||||
| SDIFFSTORE destination key1 key2 ... | 将给定所有集合的差集存储在 destination 中 |
|
| SDIFFSTORE destination key1 key2 ... | 将给定所有集合的差集存储在 destination 中 |
|
||||||
| SPOP key | 随机移除并获取指定集合中一个或多个元素 |
|
| SPOP key count | 随机移除并获取指定集合中一个或多个元素 |
|
||||||
| SRANDMEMBER key count | 随机获取指定集合中指定数量的元素 |
|
| SRANDMEMBER key count | 随机获取指定集合中指定数量的元素 |
|
||||||
|
|
||||||
更多 Redis Set 命令以及详细使用指南,请查看 Redis 官网对应的介绍:https://redis.io/commands/?group=set 。
|
更多 Redis Set 命令以及详细使用指南,请查看 Redis 官网对应的介绍:https://redis.io/commands/?group=set 。
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
---
|
||||||
|
title: Redis 3 种特殊数据结构详解
|
||||||
|
category: 数据库
|
||||||
|
tag:
|
||||||
|
- Redis
|
||||||
|
---
|
||||||
|
|
||||||
### Bitmap
|
### Bitmap
|
||||||
|
|
||||||
#### 介绍
|
#### 介绍
|
||||||
|
@ -117,7 +117,21 @@ Redis 5.0 新增加的一个数据结构 `Stream` 可以用来做消息队列,
|
|||||||
|
|
||||||
## Redis 数据结构
|
## Redis 数据结构
|
||||||
|
|
||||||
### Redis 常见的数据结构有哪些?
|
### Redis 常用的数据结构有哪些?
|
||||||
|
|
||||||
|
- **5 种基础数据类型** :String(字符串)、List(列表)、Set(集合)、Hash(散列)、Zset(有序集合)。
|
||||||
|
- **3 种特殊数据类型** :HyperLogLogs(基数统计)、Bitmap (位存储)、Geospatial (地理位置)。
|
||||||
|
|
||||||
|
关于 5 种基础数据类型的详细介绍请看这篇文章:[Redis 5 种基本数据结构详解](./redis-data-structures-01.md)。
|
||||||
|
|
||||||
|
### String 的应用场景有哪些?
|
||||||
|
|
||||||
|
- 常规数据(比如 session、token、、序列化后的对象)的缓存;
|
||||||
|
- 计数比如用户单位时间的请求数(简单限流可以用到)、页面单位时间的访问数;
|
||||||
|
- 分布式锁(利用 `SETNX key value` 命令可以实现一个最简易的分布式锁);
|
||||||
|
- ......
|
||||||
|
|
||||||
|
关于 String 的详细介绍请看这篇文章:[Redis 5 种基本数据结构详解](./redis-data-structures-01.md)。
|
||||||
|
|
||||||
### String 还是 Hash 存储对象数据更好呢?
|
### String 还是 Hash 存储对象数据更好呢?
|
||||||
|
|
||||||
@ -135,6 +149,23 @@ Redis 5.0 新增加的一个数据结构 `Stream` 可以用来做消息队列,
|
|||||||
|
|
||||||
由于购物车中的商品频繁修改和变动,这个时候 Hash 就非常适合了!
|
由于购物车中的商品频繁修改和变动,这个时候 Hash 就非常适合了!
|
||||||
|
|
||||||
|
### 使用 Redis 实现一个排行榜怎么做?
|
||||||
|
|
||||||
|
Redis 中有一个叫做 `sorted set` 的数据结构经常被用在各种排行榜的场景,比如直播间送礼物的排行榜、朋友圈的微信步数排行榜、王者荣耀中的段位排行榜、话题热度排行榜等等。
|
||||||
|
|
||||||
|
相关的一些 Redis 命令: `ZRANGE` (从小到大排序) 、 `ZREVRANGE` (从大到小排序)、`ZREVRANK` (指定元素排名)。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
[《Java 面试指北》](https://www.yuque.com/docs/share/f37fc804-bfe6-4b0d-b373-9c462188fec7) 的「技术面试题篇」就有一篇文章详细介绍如何使用 Sorted Set 来设计制作一个排行榜。
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### 使用 Set 实现抽奖系统需要用到什么命令?
|
||||||
|
|
||||||
|
- `SPOP key count` : 随机移除并获取指定集合中一个或多个元素,适合不允许重复中奖的场景。
|
||||||
|
- `SRANDMEMBER key count` : 随机获取指定集合中指定数量的元素,适合允许重复中奖的场景。
|
||||||
|
|
||||||
## Redis 线程模型
|
## Redis 线程模型
|
||||||
|
|
||||||
### Redis 单线程模型了解吗?
|
### Redis 单线程模型了解吗?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user