歡迎光臨
每天分享高質量文章

10 分鐘不全面瞭解 Redis 5.0 新特性

點選上方“芋道原始碼”,選擇“置頂公眾號”

技術文章第一時間送達!

原始碼精品專欄

 

來源:https://www.jianshu.com/p/fa989a228d59

作為一統快取江山的redis,正式釋出了5.0穩定版(stable),激不激動,開不開森?Github連結:https://github.com/antirez/redis/releases/tag/5.0.0 ,讓我們一起看看它帶來了哪些振奮人心的新特性:

redis5.0 stable

官方列舉特性如下:

======================================================
Redis 5.0.0     Released Wed Oct 17 13:28:26 CEST 2018
======================================================

what's new in Redis 5:

1. The new Stream data type. https://redis.io/topics/streams-intro
2. New Redis modules APIs: Timers, Cluster and Dictionary APIs.
3. RDB now store LFU and LRU information.
4. The cluster manager was ported from Ruby (redis-trib.rb) to C code
   inside redis-cli. Check `redis-cli --cluster help` for more info.
5. New sorted set commands: ZPOPMIN/MAX and blocking variants.
6. Active defragmentation version 2.
7. Improvemenets in HyperLogLog implementations.
8. Better memory reporting capabilities.
9. Many commands with sub-commands now have an HELP subcommand.
10. Better performances when clients connect and disconnect often.
11. Many bug fixes and other random improvements.
12. Jemalloc was upgraded to version 5.1
13. CLIENT UNBLOCK and CLIENT ID.
14. The LOLWUT command was added. http://antirez.com/news/123
15. We no longer use the "slave" word if not for API backward compatibility.
16. Differnet optimizations in the networking layer.
17. Lua improvements:
    - Better propagation of Lua scripts to replicas / AOF.
    - Lua scripts can now timeout and get in -BUSY state in the replica as well.
18. Dynamic HZ to balance idle CPU usage with responsiveness.
19. The Redis core was refactored and improved in many ways.

Redis開源社群版新特性

下麵我們對一些重要特性進行更深入的瞭解。

Streams

全新的資料型別:Streams。官方把這個當做是最重要的改進(The most important user facing improvement is without doubts the introduction
of the new general purpose data type after years: the streams.
)。而且官方提到在發版本的幾個小時前還在修複streams的問題,所以官方也不敢保證release版本是否有一些比較嚴重的BUG(T T),官方還是建議大家在生產環境不要使用streams,這樣可能會有更好的體驗,扎心了(People not using the streams can have probably a better production-ready
experience with Redis 5)。

筆者接下來還會單獨撰文剖析Streams,敬請關註。

cluster manager with c

redis終於還是拋棄了ruby,維護過redis3.x和redis4.x的都知道,主要依賴redis-trib.rb指令碼,redis5.0徹底拋棄了它,將叢集管理功能全部整合到完全用C寫的redis-cli中。可以透過命令redis-cli --cluster help檢視幫助資訊。

LOLWUT

redis5.0新增的一個命令,官方對它的描述是:a piece of art inside a database command,翻譯過來可以資料庫命令中的一件藝術品(老外真幽默)。

這個方法原始碼註釋如下:
This file implements the LOLWUT command. The command should do something
fun and interesting, and should be replaced by a new implementation at each new version of Redis。原始碼連結:https://github.com/antirez/redis/blob/5.0.0/src/lolwut5.c,有興趣的同學可以看看redis作者在5.0版本中實現了些什麼好玩的東西。

有興趣的同學還可以延伸閱讀:http://antirez.com/news/123

Lua改進

lua指令碼能更好的傳播到replicas/AOF。replicas也就是以前的slave,大家都知道redis的slave事件前段時間鬧的沸沸揚揚,現在redis官方都改稱replicas了,並且申明除非為了API向後相容,否則不再使用slave這個詞(We no longer use the “slave” word if not for API backward compatibility.)。

lua指令碼現在還能支援超時,並且可以在replica中進入BUSY狀態。

動態HZ

以前redis版本的hz都是固定的,5.0將hz動態化是為了平衡空閑CPU的使用率和響應能力。


其他一些比如HyperLogLog實現改進,RDB檔案新增儲存LFU和LRU資訊,sorted set新增兩個命令ZPOPMIN/MAX,Jemalloc升級到5.1等特性就不一一解讀了。

Redis Enterprise Software新特性

Redis開源許可從AGPL 遷移到將 Apache v2.0 與 Commons Clause 相結合的許可證,下麵介紹的這些特性不再是開源軟體,而是原始碼可用(source available)。

備註:Commons Clause 的初衷是為了抵禦一些不良行為。如那些使用原始碼,卻不對開原始碼維護做出補償的公司。” —- Commons Clause 開發者兼 FOSSA 創始人 Kevin Wang。

support docker

現在官方版本正式支援在Docker容器上部署和執行Redis叢集了。有了官方的映象,你能非常容易並快速部署幾個容器來執行一個可擴充套件的,高可用的Redis叢集。想要瞭解更多請戳連結:https://redislabs.com/redis-enterprise-documentation/getting-started/docker/。

Redis Labs’ Modules

Redis Labs開發了3個模組,並且被Redis企業軟體(簡稱RS)認證,這些模組是:
RediSearch:這個模組將RS變成了一個基於記憶體的分散式全文索引和搜尋引擎,感覺好牛逼的樣子(ES表示不服)。
ReJSON:透過模組名稱就知道,JSON作為Redis的內建資料型別。 
ReBloom: RS具有可擴充套件的Bloom過濾器,並且是一個資料型別。Bloom過濾器是一種機率性的資料結構,在快速判斷某些元素是否被包含在一個集合這方便表現的非常好。

參考

https://redislabs.com/redis-enterprise-documentation/overview/new-features-redis-enterprise/

https://raw.githubusercontent.com/antirez/redis/5.0/00-RELEASENOTES



如果你對 Dubbo / Netty 等等原始碼與原理感興趣,歡迎加入我的知識星球一起交流。長按下方二維碼噢

目前在知識星球更新了《Dubbo 原始碼解析》目錄如下:

01. 除錯環境搭建
02. 專案結構一覽
03. 配置 Configuration
04. 核心流程一覽

05. 拓展機制 SPI

06. 執行緒池

07. 服務暴露 Export

08. 服務取用 Refer

09. 註冊中心 Registry

10. 動態編譯 Compile

11. 動態代理 Proxy

12. 服務呼叫 Invoke

13. 呼叫特性 

14. 過濾器 Filter

15. NIO 伺服器

16. P2P 伺服器

17. HTTP 伺服器

18. 序列化 Serialization

19. 叢集容錯 Cluster

20. 優雅停機

21. 日誌適配

22. 狀態檢查

23. 監控中心 Monitor

24. 管理中心 Admin

25. 運維命令 QOS

26. 鏈路追蹤 Tracing

… 一共 69+ 篇

目前在知識星球更新了《Netty 原始碼解析》目錄如下:

01. 除錯環境搭建
02. NIO 基礎
03. Netty 簡介
04. 啟動 Bootstrap

05. 事件輪詢 EventLoop

06. 通道管道 ChannelPipeline

07. 通道 Channel

08. 位元組緩衝區 ByteBuf

09. 通道處理器 ChannelHandler

10. 編解碼 Codec

11. 工具類 Util

… 一共 61+ 篇

目前在知識星球更新了《資料庫物體設計》目錄如下:


01. 商品模組
02. 交易模組
03. 營銷模組
04. 公用模組

… 一共 17+ 篇


目前在知識星球更新了《Spring 原始碼解析》目錄如下:


01. 除錯環境搭建
02. IoC Resource 定位
03. IoC BeanDefinition 載入

04. IoC BeanDefinition 註冊

05. IoC Bean 獲取

06. IoC Bean 生命週期

… 一共 35+ 篇


文章轉載自公眾號:阿飛的部落格

贊(0)

分享創造快樂