介紹
Redis Labs 修改 Redis 的開源協定確實是因為它們認為一些大型雲服務提供商在沒有對計畫做出貢獻的情況下利用 Redis 賺取利潤。Redis Labs 從 Redis 7.4 版本開始,將原先的 BSD 源碼使用協定修改為 RSALv2 和 SSPLv1 協定,這一變化意味著 Redis 在 OSI(開放原始碼促進會)定義下不再被視為「開源」計畫。
Redis Labs 執行長 Ofer Bengal 曾表示,雲端運算公司利用其壟斷力量采用開源計畫而不貢獻。同時 Redis Labs 首席行銷官 Manish Gupta 指出,新的授權證 RSAL 旨在保護 Redis Labs 開發的模組,如 RedisSearch、RedisGraph 等,這些模組將不再是開源軟體,而是源碼可用(source available)級別的軟體。
Linux 基金會宣布建立 Valkey 7.2.5 的版本,這可能是對 Redis Labs 修改開源協定行為的回應。Valkey 7.2.5 是基於 Redis 7.2.4 版本 fork 出來的,旨在提供一個不受 Redis Labs 新授權證影響的 Redis 實作。
開源社群對於授權證的修改可能會有不同的反應,一些開發者和公司可能會支持這種改變,認為這有助於保護開源計畫的永續發展,而另一些人可能會對此持批評態度,認為這限制了開源精神的自由和開放性。無論如何,Redis Labs 的這一決策顯然在開源社群引起了廣泛的討論和關註。
使用
下載與解壓
wget https://github.com/valkey-io/valkey/archive/refs/tags/7.2.5.tar.gz
tar -zxvf 7.2.5.tar.gz
編譯
cd valkey-7.2.5
make
安裝
這通常需要幾分鐘才能完成。測試完成後,輸入以下命令將二進制檔安裝到系統上:
sudo make install
輸出以下提示表示安裝成功啦!
Hint: It's a good idea to run 'make test' ;)
INSTALL valkey-server
INSTALL valkey-benchmark
INSTALL valkey-cli
INSTALL SYMLINK redis-server -> valkey-server
INSTALL SYMLINK redis-cli -> valkey-cli
INSTALL SYMLINK redis-benchmark -> valkey-benchmark
INSTALL SYMLINK redis-check-rdb -> valkey-check-rdb
INSTALL SYMLINK redis-check-aof -> valkey-check-aof
INSTALL SYMLINK redis-sentinel -> valkey-sentinel
啟動
/usr/local/bin/valkey-server /etc/valkey/valkey.conf
發現本地埠
6379
被原有Redis占用,這裏使用其他埠
6378
。再次啟動就正常啦
服務
為了更好地控制Valkey的管理方式,您可以建立一個systemd單元檔,使其可以作為systemd服務。這樣做的好處是可以伺服器啟動時啟動Valkey。
建立並開啟
/etc/systemd/system/valkey.service
檔:
[Unit]
Description=Valkey a new project to resume development on the formerly open-source Redis project
After=network.target
[Service]
User=redis
Group=redis
ExecStart=/usr/local/bin/valkey-server /etc/valkey/valkey.conf
ExecStop=/usr/local/bin/valkey-cli shutdown
Restart=always
[Install]
WantedBy=multi-user.target
輸入以下命令啟動systemd服務
sudo systemctl start valkey.service
執行以下命令檢查服務有沒有錯誤
sudo systemctl status valkey.service
輸出以下內容表示服務啟動成功
● valkey.service - Valkey a new project to resume development on the formerly open-source Redis project
Loaded: loaded (/etc/systemd/system/valkey.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2024-04-2323:21:29 CST; 13min ago
Main PID: 26924 (valkey-server)
Tasks: 5 (limit: 4915)
CGroup: /system.slice/valkey.service
└─26924 /usr/local/bin/valkey-server 127.0.0.1:6378
Apr 2323:21:29 wt-test-develop valkey-server[26924]: 26924:C 23 Apr 202423:21:29.735 * Valkey version=7.2.5, bits=64, commit=000
Apr 2323:21:29 wt-test-develop valkey-server[26924]: 26924:C 23 Apr 202423:21:29.735 * Configuration loaded
Apr 2323:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 202423:21:29.736 # You requested maxclients of 10000 requiri
Apr 2323:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 202423:21:29.736 # Server can't set maximum open files to 10
Apr 23 23:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 2024 23:21:29.737 # Current maximum open files is 4096. maxcl
Apr 23 23:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 2024 23:21:29.737 * monotonic clock: POSIX clock_gettime
Apr 23 23:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 2024 23:21:29.737 # Failed to write PID file: Permission deni
Apr 23 23:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 2024 23:21:29.738 * Running mode=standalone, port=6378.
Apr 23 23:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 2024 23:21:29.741 * Server initialized
Apr 23 23:21:29 wt-test-develop valkey-server[26924]: 26924:M 23 Apr 2024 23:21:29.742 * Ready to accept connections tcp
客戶端
要測試您的服務是否正常執行,請使用命令列客戶端連線到
Valkey
伺服器。
$ valkey-cli -p 6378
127.0.0.1:6378> set name "Tinywan"
OK
127.0.0.1:6378> get name
"Tinywan"
127.0.0.1:6378>
由於客戶端跟Redis完全一樣,埠和提示資訊也一樣,所以可以直接使用Redis客戶端連線
$ redis-cli -p 6378
127.0.0.1:6378> keys *
1) "name"
127.0.0.1:6378> get name
"Tinywan"
127.0.0.1:6378>
效能測試
在 Redis 安裝完畢後會自動安裝一個
redis-benchmark
測試工具,其是一個壓力測試工具,用於測試 Redis 的效能。同理在安裝完成
Valkey
後也會生成一個
valkey-benchmark
測試工具。
valkey-benchmark
valkey-benchmark -h 127.0.0.1 -p 6378 -n 10000 -c 20 -q
PING_INLINE: 45248.87 requests per second, p50=0.143 msec
PING_MBULK: 31545.74 requests per second, p50=0.359 msec
SET: 28409.09 requests per second, p50=0.607 msec
GET: 31645.57 requests per second, p50=0.343 msec
INCR: 29940.12 requests per second, p50=0.375 msec
LPUSH: 30487.80 requests per second, p50=0.439 msec
RPUSH: 30864.20 requests per second, p50=0.407 msec
LPOP: 33670.04 requests per second, p50=0.167 msec
RPOP: 24154.59 requests per second, p50=0.479 msec
SADD: 31250.00 requests per second, p50=0.351 msec
HSET: 47169.81 requests per second, p50=0.143 msec
SPOP: 42918.46 requests per second, p50=0.151 msec
ZADD: 30959.75 requests per second, p50=0.287 msec
ZPOPMIN: 48076.92 requests per second, p50=0.143 msec
LPUSH (needed to benchmark LRANGE): 49019.61 requests per second, p50=0.143 msec
LRANGE_100 (first 100 elements): 15600.62 requests per second, p50=0.551 msec
LRANGE_300 (first 300 elements): 6968.64 requests per second, p50=1.351 msec
LRANGE_500 (first 500 elements): 4466.28 requests per second, p50=2.031 msec
LRANGE_600 (first 600 elements): 3821.17 requests per second, p50=2.439 msec
MSET (10 keys): 32467.53 requests per second, p50=0.487 msec
XADD: 31446.54 requests per second, p50=0.479 msec
redis-benchmark
redis-benchmark -h 127.0.0.1 -p 6378 -n 10000 -c 20 -q
PING_INLINE: 42735.04 requests per second, p50=0.159 msec
PING_MBULK: 46511.63 requests per second, p50=0.143 msec
SET: 34843.21 requests per second, p50=0.151 msec
GET: 49019.61 requests per second, p50=0.143 msec
INCR: 46511.63 requests per second, p50=0.143 msec
LPUSH: 44052.86 requests per second, p50=0.143 msec
RPUSH: 33222.59 requests per second, p50=0.287 msec
LPOP: 23419.21 requests per second, p50=0.655 msec
RPOP: 43668.12 requests per second, p50=0.143 msec
SADD: 35087.72 requests per second, p50=0.159 msec
HSET: 32786.88 requests per second, p50=0.351 msec
SPOP: 26954.18 requests per second, p50=0.623 msec
ZADD: 23752.97 requests per second, p50=0.615 msec
ZPOPMIN: 23696.68 requests per second, p50=0.615 msec
LPUSH (needed to benchmark LRANGE): 31347.96 requests per second, p50=0.391 msec
LRANGE_100 (first 100 elements): 16051.36 requests per second, p50=0.959 msec
LRANGE_300 (first 300 elements): 7082.15 requests per second, p50=1.375 msec
LRANGE_500 (first 500 elements): 4679.46 requests per second, p50=1.991 msec
LRANGE_600 (first 600 elements): 4004.81 requests per second, p50=2.295 msec
MSET (10 keys): 27247.96 requests per second, p50=0.519 msec
XADD: 24449.88 requests per second, p50=0.455 msec
簡單比較
資料庫 | PING | SET | GET | SPOP | ZPOPMIN | XADD |
---|---|---|---|---|---|---|
Redis | 42735.04 | 34843.21 | 49019.61 | 26954.18 | 23696.68 | 24449.88 |
Valkey | 45248.87 | 28409.09 | 31645.57 | 42918.46 | 48076.92 | 23752.97 |