Redis SETNX Command Explained

The Redis SETNX command sets a key to a given value, but only if the key doesn’t already exist. If the key already holds a value, no operation is performed.

Note: The SET command can do the same thing, and it’s possible that the SETNX command may be deprecated at some point. Therefore, it’s probably a good idea to use SET instead of SETNX if possible.

Read more

Redis MSETNX Command Explained

In Redis, the MSETNX command allows us to set multiple keys at once, but only if none of them exist.

This allows us to set multiple keys representing different fields of a single logical object in a way that ensures that either all the fields are set, or none are set.

Read more

SQL Server CASE Statement

The SQL Server CASE statement evaluates a list of conditions and returns one of multiple possible result expressions.

Although it’s commonly known as the “CASE statement”, the SQL Server documentation lists it as an expression. Plus it’s referred to as the “CASE expression” in the SQL standard. Some other DBMSs distinguish between the CASE statement and the CASE expression. Either way, here’s a quick rundown on how the “CASE statement” (or CASE expression) works in SQL Server.

Read more

Redis SET Command Explained

In Redis, the SET command sets a key to hold a given string value.

If the key already holds a value, it is overwritten with the new value. Also, any previous time to live associated with the key is discarded (assuming a successful SET operation).

Read more

SQL NVL2() Explained

Some DBMSs have an NVL2() function that allows us to replace a value with another value, the new value being determined by whether or not the initial value is null.

It’s similar to the NVL() function, except that NVL2() accepts exactly three arguments. This allows us to specify a different value to return in the event the first argument is not null.

In contrast, with the NVL() function, some DBMSs accept only two arguments (which makes the function a synonym for the IFNULL() function) while others accept an unlimited number of arguments (which makes it a synonym for the COALESCE() function).

Read more