0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Redisの期限切れキーについて

Last updated at Posted at 2019-10-08

Redisのexpire設定について

Redisのキーに、有効期限の設定方法。

> set test 12345
OK
> EXPIRE test 300
(integer) 1
> ttl test
(integer) 294

Redisの期限切れキーについて

キーの期限切れ削除方法は、受動的方法と能動的方法の2つ。

  • キーがアクセスされたタイミングで削除
    キーがアクセスされたタイミングで、タイムアウトを確認する。
  • 自動削除
    2度とアクセスされない期限切れキーは、永遠に残ってしまうので以下の手順で削除
    Redisは、以下の操作を1秒間に10回行う。
    1. キーセットから20個のキーをランダムに取得
    2. 期限切れキーを削除
    3. 期限切れキーが25%以上ある場合は、1から繰り返す
      期限切れのキーが25%未満になるまで繰り返されます。

気づき

Redisで、keys *を実行した時にアイテムカウントが一気に減少したのは、全部のキーにアクセスして残りの25%のものが削除されたからなのか。

Redisのメモリを使い果たしたときの動作

maxmemory-policyで設定できる。
allkeys-lru : 全部のキーで、参照されていない時間が長いものから削除
noeviction : エラー返却
etc...

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?