0
0
Redisquery~5 mins

HINCRBY for numeric fields in Redis - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the Redis command HINCRBY do?

HINCRBY increments the integer value of a field in a hash by a given number. If the field does not exist, it is set to 0 before the increment.

Click to reveal answer
beginner
What happens if you use HINCRBY on a field that does not exist in the hash?

The field is created with the value 0, then incremented by the specified amount.

Click to reveal answer
beginner
Can HINCRBY be used to decrement a numeric field in a Redis hash?

Yes, by passing a negative number as the increment, HINCRBY can decrement the field's value.

Click to reveal answer
intermediate
What error occurs if you try to use HINCRBY on a field that contains a non-integer value?

Redis returns an error because HINCRBY only works with integer values.

Click to reveal answer
beginner
Example: What is the result of HINCRBY user:1 visits 3 if visits was 5 before?

The new value of visits will be 8 (5 + 3).

Click to reveal answer
What does HINCRBY myhash field 10 do if field does not exist?
ADoes nothing
BReturns an error
CCreates <code>field</code> with value 10
DCreates <code>field</code> with value 0
Which data type must the field value be for HINCRBY to work?
ASet
BString
CList
DInteger
What happens if you run HINCRBY myhash field -2?
AIncrements <code>field</code> by 2
BDecrements <code>field</code> by 2
CDeletes <code>field</code>
DReturns an error
If field contains the string "hello", what happens when you run HINCRBY myhash field 1?
ARedis returns an error
BField becomes 1
CField becomes "hello1"
DField is deleted
What is the return value of HINCRBY after incrementing a field?
AThe new value after increment
BThe increment amount
CAlways 0
DThe old value before increment
Explain how the Redis command HINCRBY works with numeric fields in a hash.
Think about how you add or subtract numbers in a table of values.
You got /4 concepts.
    What errors or limitations should you be aware of when using HINCRBY?
    Consider what happens if you try to add numbers to words.
    You got /3 concepts.