> For the complete documentation index, see [llms.txt](https://tommyyang.gitbook.io/javainterview/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://tommyyang.gitbook.io/javainterview/architecture/redis.md).

# Redis

Redis 作为一种 KV 缓存服务器，有着极高的性能，相对于 Memcache，Redis 支持更多种数据类型，因此在业界应用广泛。

## 性能高的原因

* 纯内存操作
* 单线程
* 高效的数据结构
* 合理的数据编码
* 其他方面的优化

## 适用场景

在 Redis 中，常用的 5 种数据结构和应用场景如下：

* String：缓存、计数器、分布式锁等。
* List：链表、队列、微博关注人时间轴列表等。
* Hash：用户信息、Hash 表等。
* Set：去重、赞、踩、共同好友等。
* ZSet：访问量排行榜、点击量排行榜等。

## 数据结构分析

### SDS

### 字典

### 跳跃表

### List

### Set

### ZSet
