Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redis pipelined order of execution

Tags:

ruby

redis

I am using rub redis gem. Wondering if I do for example:

redis.pipelined do
    REDIS.del("users:#{current_user_id}:i-unread")
    REDIS.lpush("users:#{current_user_id}:i-read", items)
    REDIS.ltrim("users:#{current_user_id}:i-read", 0, Interaction::MAX_INTERACTIONS)
end

is this order of execution guaranteed?

like image 447
0xSina Avatar asked Jul 13 '13 22:07

0xSina


People also ask

How does Redis pipelining work?

Redis pipelining is a technique for improving performance by issuing multiple commands at once without waiting for the response to each individual command. Pipelining is supported by most Redis clients. This document describes the problem that pipelining is designed to solve and how pipelining works in Redis.

Is Redis sequential?

Redis Transactions make two important guarantees: All the commands in a transaction are serialized and executed sequentially.

How are Redis pipelining and transaction different?

Unlike pipelines, pipelines use special commands to mark the beginning and the end of the transaction, and the server also can queue the commands from a transaction (so the client can send one at a time). So transactions are stateful on the server, it actually keeps track of an ongoing transaction.

How does Redis Multi work?

The multi command tells Redis to begin a transaction block. Any subsequent commands will be queued up until you run an exec command, which will execute them.


1 Answers

of course the order is guaranteed, otherwise pipelining would be useless. you can always look at the code. for example, this test clearly assumes that the commands are executed sequentially: https://github.com/redis/redis-rb/blob/master/test/pipelining_commands_test.rb#L32

def test_bulk_and_multi_bulk_commands_mixed
  r.pipelined do
    r.lpush "foo", "s1"
    r.lpush "foo", "s2"
    r.mset("baz", "s3", "qux", "s4")
  end

  assert_equal 2, r.llen("foo")
  assert_equal "s2", r.lpop("foo")
  assert_equal "s1", r.lpop("foo")
  assert_equal "s3", r.get("baz")
  assert_equal "s4", r.get("qux")
end
like image 112
akonsu Avatar answered Oct 20 '22 20:10

akonsu