1. Why Redis
首先,我们来看一下官方的解释
Redis is an open source (BSD licensed), in-memory data structure store used as a database, cache, message broker, and streaming engine. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.
You can run atomic operations on these types, like appending to a string; incrementing the value in a hash; pushing an element to a list; computing set intersection, union and difference; or getting the member with highest ranking in a sorted set.
To achieve top performance, Redis works with an in-memory dataset. Depending on your use case, Redis can persist your data either by periodically dumping the dataset to disk or by appending each command to a disk-based log. You can also disable persistence if you just need a feature-rich, networked, in-memory cache.
Redis supports asynchronous replication, with fast non-blocking synchronization and auto-reconnection with partial resynchronization on net split.
Redis also includes:
- Transactions
- Pub/Sub
- Lua scripting
- Keys with a limited time-to-live
- LRU eviction of keys
- Automatic failover
You can use Redis from most programming languages.
下面我们来通俗的讲一下吧
在我们日常的 Web 开发中,无不都是使用数据库来进行数据的存储,由于一般的系统任务中通常不会存在高并发的情况,所以这样看起来并没有什么问题,可是一旦涉及大数据量的需求,比如一些商品抢购的情景,或者是主页访问量瞬间较大的时候,单一使用数据库来保存数据的系统会因为面向磁盘,磁盘读/写速度比较慢的问题而存在严重的性能弊端,一瞬间成千上万的请求到来,需要系统在极短的时间内完成成千上万次的读/写操作,这个时候往往不是数据库能够承受的,极其容易造成数据库系统瘫痪,最终导致服务宕机的严重生产问题。而 Redis 则是建立在内存上的一种 NoSQL ,具有高速读写的能力,因此,我们可以通过 Redis 来处理短时间内大量的请求,可以将其看成是链接 Web 与数据库之间的一个数据的中转站。
2. Install Redis on macOS
既然在 Mac 上安装软件必然跑不掉 homebrew 啦,我们就来看一下如何在 Mac 上通过 brew 来安装 Redia 吧
-
下载
brew install redis
-
Starting and stopping Redis in the foreground
redis-server
-
Starting and stopping Redis using launchd
# Starting
brew services start redis
# Stopping
brew services stop redis
-
Connect to Redis
redis-cli
And then, 你可以放心大胆的品尝 Redis 啦~~~