redis.pop: Redis queues

Description Usage Arguments Details Value Note Author(s) See Also

View source: R/redis.R

Description

redis.push pushes an element to the list

redis.pop pops and element from the list

Usage

1
2
redis.pop(rc, keys, timeout=0, r2l=TRUE)
redis.push(rc, key, value, r2l=TRUE)

Arguments

rc

redis connection handle as returned by redis.connect

keys

character vector of keys. Note that Redis only supports non-blocking POP for singe key, so must be a string if timeout is greater than 0, see Details.

timeout

integer >= 0 or Inf. Time out (in seconds) for the POP operation. If 0 then non-blocking POP is performed.

r2l

logical, if TRUE then the operation is right-to-left, i.e. right push, left pop. If FALSE then the operation is left-to-roght (left push, right pop).

key

string, key

value

value to push. Currently, only string values are supported adn they are stored as-is. Multiple values are allowed which corresponds to multiple operations.

Details

redis.push pushes an element into a list and redis.pop retrieves elements from the list. This pair of operations is commonly used to implement queues. If timeout is 0 then only a single key can be provided and the operation will return NULL if the list is empty, otherwise one element is popped. If timeout is > 0 then a list of keys can be provided and it will return the moment an element is available in any of the lists (see Redis documentation on BLPOP for exact details). If the timeout value is not finite, then it blocks forever.

If you think of a FIFO queue, r2l determines the direction in which the queue will work. If TRUE then elements are pushed on the right and popped on the left (most common). You can implement a LIFO queue by using the inverse value for pop vs push (e.g., r2l=FALSE for push and r2l=TRUE for pop which will make the queue entry and exit on the left).

Note that the current implementation only supports direct string values in redis.push. Also

Value

redis.pop non-blocking version returns the obtained object or NULL if the list is empty. Blocking operation returns named vector with the obtained element bearing the name of the key from which it was obtained.

redis.push returns the number of items in the list

Note

rediscc was originally written as a replacement of rredis so it shares the serialized value format which has a few odd implications. rredis doesn't store values directly, but uses R serialization to store the serialized content in the value. On the plus side it means that arbitrary values can be stored, but it also means that storing an integer into a key will result in the storage of a binary blob such that seemingly intuitive actions like incrementing it don't work since Redis doesn't recognize it as a number. Also it means that it is possible to store the value NULL in the key but this is not distinguishable from the deleted key since redis.get will return NULL in both cases.

Author(s)

Simon Urbanek

See Also

redis.connect


s-u/rediscc documentation built on July 22, 2020, 2:18 a.m.