17
5

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のpipelineとmultiの違い

Last updated at Posted at 2019-08-29

RedisのPipelineとMulti/Execは、名前の雰囲気が似ているし機能も似ているが、中身は全然違う。

Pipelineはただの複数実行で、Multi/Execはトランザクション内での実行になるという違いがある。

PipelineとMulti/Execの違い

Pipeline

複数のコマンドを結果を待たずに送信する。その結果、ネットワークに由来する待ち時間を減らす効果がある。複数のクライアントが接続している状況では、タイミングによってはPipelineで指定された複数コマンドの間に他のコマンドが入ってしまう可能性がある。

クライアントライブラリが実装している機能であり、Redis本体にこの機能があるわけではない。

Pipelineの例(Ruby)
redis.pipelined do
  redis.set(key, value)

  # ここに他のコマンドが入る可能性がある

  redis.set(key, value)
end

Multi

複数のコマンドを1つのトランザクション内で実行する。複数のクライアントが接続している状況であっても、Multiで指定された複数のコマンドの間に他のコマンドが入り込むことはない。

Multiは開始、Execは実行を意味する。Redis本体に実装された機能。

Multi/Execの例(Ruby)
redis.multi do
  redis.set(key, value)

  # ここに他のコマンドが入る可能性はない

  redis.set(key, value)
end

参考リンク

redis-rb
Redis - Transactions

17
5
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
17
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?