Skip to content

Commit

Permalink
Merge pull request #67 from reneklacan/pipeline-timeout
Browse files Browse the repository at this point in the history
Allow to specify timeout for pipeline command
  • Loading branch information
artemeff authored Jul 19, 2016
2 parents c6f41d8 + dd105bc commit 69274de
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/exredis.ex
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,13 @@ defmodule Exredis do
@spec query_pipe(pid, [list]) :: any
def query_pipe(client, command) when (is_pid(client) or is_atom(client)) and is_list(command), do:
client |> :eredis.qp(command) |> Enum.map(&elem(&1, 1))

@doc """
Performs a pipeline query with specified timeout, executing the list of commands
query_pipe(client, [["SET", :a, "1"], ["LPUSH", :b, "3"]], 10)
"""
@spec query_pipe(pid, [list], float) :: any
def query_pipe(client, command, timeout) when (is_pid(client) or is_atom(client)) and is_list(command) and is_integer(timeout), do:
client |> :eredis.qp(command, timeout) |> Enum.map(&elem(&1, 1))
end
8 changes: 8 additions & 0 deletions test/exredis_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,14 @@ defmodule ExredisTest do
assert status == ["OK", "1", "2"]
end

test "pipelining with explicit timeout" do
query = [["SET", :a, "1"], ["LPUSH", :b, "3"], ["LPUSH", :b, "2"]]
{:ok, client} = E.start_link

status = E.query_pipe(client, query, 10)
assert status == ["OK", "1", "2"]
end

test "explicit timeout", ctx do
{reason, _} = catch_exit(ctx[:c] |> E.query(["INFO"], 0))
assert reason == :timeout
Expand Down

0 comments on commit 69274de

Please sign in to comment.