クラウドデータベース Redis バージョン 4.0 は、Redis コミュニティーバージョン 4.0 のエンジンに基づいており、Alibaba Cloud で開発された多数の機能と組み合わされ、新しい販売向けバージョンのリリース後に多くのバグが修正されています。 Redis 2.8 は除外されます。 エンジンのすべての利点に加えて、これらの新機能も提供されます。

Lazyfree

Redis 4.0 の lazyfree メカニズムでは、サービスの安定性を向上させるため、DEL、FLUSHDB、FLUSHALL、RENAME などのコマンドによって発生する Redis サーバーのブロッキングが回避されます。

UNLINK

Redis 4.0 より前のバージョンでは、Redis での DEL コマンドの実行については、すべてのキーのメモリがリリースされるまで結果が戻りません。 そのため、キーが大量にある場合は (たとえば、ハッシュ内に 10,000,000 個のデータがある場合)、他の接続は長時間待機する必要があります。 既存の DEL セマンティクスとの互換性のために、 Redis 4.0 では UNLINK コマンドが導入されています。 DEL コマンドと効果と使用方法は同じですが、メモリリリースはバックグラウンドスレッドで実行されます。

Unlink key [Key...]

FLUSHDB と FLUSHALL

Redis 4.0 では、FLUSHDB コマンドと FLUSHALL コマンドに、 lazyfree を使用するかどうかを指定するオプションが新たに追加されています。 以下はメモリ全体を空にする方法です。

Flushall [async]
3) flushdb [async]

RENAME

RENAME oldkey newkey コマンドの実行時、すでに newkey が存在している場合は、 既存の newkey が削除されます。これによって、前述のように大きなキーを削除してしまう問題も発生します。 このシナリオで、lazyfree を使用して Redis で削除する場合、コンソールで以下の設定を有効にします。

Lazyfree-Lazy-server-del yes/no
このパラメーターの設定はコンソールで有効にできません。

データの削除または除外

ユーザーはデータの有効期限を設定し、期限切れのデータを削除するために Redis のリタイアメントメカニズムを利用しますが、この場合にも、大きなキーを削除すると CPU プロセスが不安定になるという、前述の問題があります。 Redis 4.0 では 2 つの設定があり、外部またはデータの外側にあるときに Redis で lazyfree が使用されます。

Lazyfree-Lazy-Eviction yes/no
Lazyfree-Lazy-expand yes/no

追加されたコマンド

SWAPDB

SWAPDB コマンドを使用すると 2 つの DB のデータが置換され、SWAPDB コマンドの実行後、新しいデータを表示するために DB に接続し、SELECT を実行する必要はありません。

Wagner .0kev.1: 6379> select 0
OK
Wagner .0.0.1: 6379> set key value0
OK
Wagner .0kev.1: 6379> select 1
OK
Wagner .0.0.1: 6379 [1]> set key value1
OK
Wagner .0.0.1: 6379 [1]> swapdb 0 1
OK
Wagner .0.0.1: 6379 [1]> get key
"Value0"
Wagner .0.0.1: 6379 [1]> select 0
OK
Wagner .0.0.1: 6379> get key
"Value1"

ZLEXCOUNT

ZLEXCOUNT コマンドはソート設定に使用されます。 ZRANGEBYLEX コマンドと似ていますが、ZRANGEBYLEX コマンドがメンバを返すのと異なり、ZLEXCOUNT コマンドでは条件付きの メンバの数が返されます。

MEMORY

Redis 4.0 より前のバージョンでは、INFO MEMORY コマンドだけが、Redis の制限されたメモリ情報を把握するために使用されていました。Redis 4.0 のMEMORY コマンドは、Redis のメモリステータスを完全に把握するのに役立ちます。

Wagner .0.0.1: 6379> memory help
1) "memory doctor-outputs memory problems Report"
2) "memory usage <key> [samples <count>]-estimate memory usage of key"
3) "memory stats-show memory usage details"
4) "memory purge-ask the allocator to release memory"
5) "memory malloc-stats-show locator or internal stats"
  • MEMORY USAGE

    USAGE サブコマンドでは、Redis 内で実際にキーがどれだけのメモリを占有しているかが表示されます。 以下の 2 つの点に注意します。

    • キーだけでなく、値もメモリを必要としますが、Redis ではデータを管理するためにもメモリが必要です。

    • ハッシュ、リスト、セット、ソートセットなどのキータイプについては、結果はサンプリングされて計算され、 SAMPLES オプションを介してサンプルの数を調節します。

  • Memory stats
    27.0.0.1: 6379> memory stats
           1) "peak. allocated "// redis from startup to the present, How much memory has history used at most?
           1) (integer) 423995952
           3) "total. allocated" // currently in use memory
           6) (integer) 11130320
           5) "startup. allocated" // redis takes up memory after startup Initialization
           4) (integer) 9942928
           7) "replication. backlog "// will be used when the master disconnects from replication to reconnect, default of 10 MB
           6) (integer) 1048576
           9) memory used by "Clients. Slaves" // master-slave Replication
          16) (integer) 16858
          11) read and write buffer for "Clients. Normal" // regular user Client
          14) (integer) 49630
          13) "Aof. buffer "// aof cache used for persistence and the sum of the cache generated by aofrewrite
          4) (integer) 3253
          15) "DB. 0 "// memory occupied by metadata for each DB
          16) 1) "overhead. hashtable. Main"
              1) (integer) 5808
              3) "overhead. hashtable. expires "// manage additional memory consumption for data with expiration time
              6) (integer) 104
          17) "overhead. Total" // sum of the memory consumption mentioned above
          12) (integer) 11063904
          19) "keys. Count" // The total amount of Key currently stored
          20) (integer) 94
          21) "keys. bytes-per-key" // average per key size in current Memory
          12631 22) (integer)
          23) "dataset. bytes "// memory occupied by user data (= total memory-memory used by redis metadata)
          12) (integer) 66416
          25) "dataset. percentage "// 100 * dataset. bytes/(total. allocated-startup. allocated)
          26) 5.5934348106384277"
          27) "peak. Percentage" // 100 * Total. Located/FIG
          28) 2.6251003742218018"
          29) "Fragmentation" // memory fragmentation Rate
          30) 1.1039986610412598"
  • MEMORY DOCTOR

    主にメモリ関連の問題に対する診断上の推奨事項を示し、潜在的な問題をあらかじめ特定するために使用されます。

    Peak memory: peak. Allocated/total. Allocated> 1.5, at which time the memory fragmentation rate may be relatively high
      High fragmentation: fragmentation> 1.4 at a time when the fragmentation rate is relatively high
      Big slave buffers: the average memory for each slave buffer exceeds 10 MB, the reason may be that the master write traffic is too high
      Big client buffers: the average memory of a regular client buffer exceeds 200kb, the reason may be that pipeline is using incorrectly or that pub/sub client processing messages is not timely.
  • MALLOC STATS と MALLOC PURGE

    これら 2 つのコマンドは、jemalloc を操作するために使用されます。jemalloc を使用する場合にのみ有効です。

LFU メカニズムおよびホットキー

Redis 4.0 では allkey-LFU および volatile-LFU の両方のデータ削除ポリシーが追加され、OBJECT コマンドが使用されます。 キーへのアクセス頻度を取得するコマンドです。

Object freq user_key

LFU メカニズムに基づいて、ユーザーはホットスポットキーを見つけるために SCAN コマンドと OBJECT FREQ コマンドを使用します。Redis では、同時に優れたツールがリリースされています。 Redis-CLI は、以下の例のように使用します。

$./Redis-cli -- hotkeys
# Scanning the entire keyspace to find hot keys as well
# Average sides per key type.  You can use-I 0.1 to sleep 0.1 Sec
# Per 100 scan commands (not usually needed ).
[00.00%] Hot key'counter: 000000000002 'found so far with counter 87
[00.00%] Hot key'key: 000000000001 'found so far with counter 254
[00.00%] Hot Key 'mylist' found so far with counter 107
[00.00%] Hot key'key: 000000000000 'found so far with counter 254
[45.45%] Hot key'counter: 000000000001 'found so far with counter 87
[45.45%] Hot key'key: 000000000002 'found so far with counter 254
[45.45%] Hot key'myset' found so far with counter 64
[45.45%] Hot key'counter: 000000000000 'found so far with counter 93
-Summary -------
Sampled 22 keys in the keyspace!
Hot Key found with counter: 254 keyname: Key: 000000000001
Hot Key found with counter: 254 keyname: Key: 000000000000
Hot Key found with counter: 254 keyname: Key: 000000000002
Hot Key found with counter: 107 keyname: mylist
Hot Key found with counter: 93 keyname: Counter: 000000000000
Hot Key found with counter: 87 keyname: Counter: 000000000002
Hot Key found with counter: 87 keyname: Counter: 000000000001
Hot Key found with counter: 64 keyname: myset