Database Reference
In-Depth Information
The “Implementing a Reliable Queue” example demonstrates pushing
several items onto the queue list. Next an element is moved from the
queue list to the processing list. Finally, the element is removed
from the processing list.
When implementing this using a client, it is usually more common to
use the BRPOPLPUSH command. This is a blocking version of the
normal command that will wait until an element is pushed onto the list.
This avoids the need to poll on the client side. The command supports a
timeout feature in case the client needs to perform some other function.
Another client is usually implemented to handle elements that have
been placed on the processing list but never removed. The cleanup
client can periodically scan the list, and if it sees an element twice, push
it back onto the queue list for reprocessing. There is no need to remove
the original item from the processing queue, a successful LREM will
remove all copies of the element and the processing queue should
generally remain small, so size is not a concern.
The other two data types implemented by Redis are Sets and Sorted Sets.
Like the Java Set collection, these data structures maintain lists of distinct
values.MostoftheSetandSortedSetoperationshave O(n) processingtime
in the size of the set.
Basic sets are fairly simple constructs and useful for keeping track of unique
events or objects in a real-time stream. This can become infeasible when the
size of the set gets very large, mostly due to the space requirements, which
are linear in the number of unique elements in the set. Adding elements
to the set is accomplished through the SADD command, which takes a KEY
and any number of elements to add. It returns the number of elements
newly added to the set. Elements are deleted from the set using the SREM
command. It has the same arguments as the SADD command. The SPOP
command works similarly to SREM , but returns and removes a random
element from the set. The SMOVE command combines the SADD and SREM
commands into a single atomic operation to move elements between two
different sets.
Set membership queries are done using the SISMEMBER command. This
command, unfortunately, only takes a single element as its argument. To
Search WWH ::




Custom Search