This predicate is overloaded to handle two types of requests. First, it
is a shorthand for redis(Connection, Command, _)
and
second, it can be used to exploit Redis pipelines and transactions.
The second form is acticated if Request is a list. In
that case, each element of the list is either a term Command -> Reply
or a simple
Command. Semantically this represents a sequence of redis/3
and
redis/2 calls. It differs in the
following aspects:
- All commands are sent in one batch, after which all replies are
read. This reduces the number of round trips and typically
greatly improves performance.
- If the first command is
multi
and the last exec
,
the commands are executed as a Redis transaction, i.e., they are
executed atomically.
- If one of the commands returns an error, the subsequent commands
are still executed.
- You can not use variables from commands earlier in the list for
commands later in the list as a result of the above execution order.
Procedurally, the process takes the following steps:
- Send all commands
- Read all replies and push messages
- Handle all callbacks from push messages
- Check whether one of the replies is an error. If so, raise this
error (subsequent errors are lost)
- Bind all replies for the
Command -> Reply
terms.
Examples
?- redis(default,
[ lpush(li,1),
lpush(li,2),
lrange(li,0,-1) -> List
]).
List = ["2", "1"].