Database Reference
In-Depth Information
1 for the former or the value specified by the command. In both cases,
the string value contained within the key is interpreted as a 64-bit signed
integer for the purposes of arithmetic. Decrementing a counter is handled
by the DECR and DECRBY commands. The INCRBYFLOAT command works
like INCRBY , except that the string contained in the value is interpreted as a
double-precision floating-point value.
Atomic counters for hash tables operate on subkeys. Rather than implement
the full suite of counter commands, hash tables only implement a variant
of INCRBY and INCRBYFLOAT , called HINCRBY and HINCRBYFLOAT ,
respectively.
Tip
At first glance, a Hash with its subkeys is unnecessary because there is
already a key-value store. However, there are many cases where using a
hash makes more sense than simply using keys. First, if there are a few
different metrics to be stored, the Hash storage mechanism can actually
be more efficient than using separate keys. This is because Redis' hash
table implementation uses ziplists for small hashes to improve storage
performance. Second, if these metrics are all related then the HGETALL
command can be used to retrieve all of the metrics in a single
command. The nature of the hash structure still lets all of the keys be
updated independently so there is no real disadvantage. Finally, it is
common to expire data in the Redis database after some time. Largely,
this is done to control the memory footprint of the database. Using a
hash table means only having to expire a single key, which helps to
maintain consistency in reporting.
The list data structure in Redis is often used to implement various
queue-like structures. This is reflected in the command set for the list data
type, which is focused on pushing and popping elements from the list.
The basic commands are LPUSH ( RPUSH ) and LPOP ( RPOP ). Redis lists are
bidirectional, so the performance is the same for both left and right inserts.
Using the same “side” of command (for example, LPUSH and LPOP ) results
in stack, or Last-In-First-Out (LIFO), semantics. Using opposite-sided
Search WWH ::




Custom Search