In Redis, the GET
command is typically used to return the value of a single key that holds a string. But what if we need the values from multiple keys?
We can use the MGET
command.
In Redis, the GET
command is typically used to return the value of a single key that holds a string. But what if we need the values from multiple keys?
We can use the MGET
command.
Many SQL databases have a SUBSTR()
or equivalent function that returns a substring from a specified string.
Redis has a SUBSTR
command, but it was deprecated in Redis 2.0.0.
However, Redis also has the GETRANGE
command, that basically does the same thing. Basically, anything that was possible with the Redis SUBSTR
command, is now possible with the GETRANGE
command.
And the GETRANGE
command does basically the same thing that most of the SUBSTR()
and SUBSTRING()
functions do in the SQL world – gets a substring from a string.
The INCR
command is commonly used in Redis to increment a value by one. And the INCRBY
command can be used to increment a valued by a specified integer. But neither of those commands let us work with floating point numbers.
If we want to use floating point numbers, we can use the INCRBYFLOAT
command.
Redis provides us with a convenient way to set multiple strings at once. Specifically, the MSET
command enables us to set multiple strings in one go.
There’s also the MSETNX
command which does the same thing, but only if none of the keys already exist.
The Redis CLI allows us to easily run a command multiple times. All we need to do is prefix the command with the number of times we want it to run.
Continue readingIn Redis, the GETRANGE
command allows us to get part of a string at a given key, starting and ending at the specified offsets.
The GETRANGE
command replaced the SUBSTR
command, which basically does the same thing. The SUBSTR
command is now considered deprecated (as of Redis 2.0.0).
In Redis, the SETRANGE
command allows us to overwrite part of a string at a given key, starting at a specified offset. It overwrites the old value from the specified offset, for the entire length of the new value.
In Redis, the DECRBY
command decrements the value of a key by the specified amount.
If the key doesn’t exist, DECRBY
creates the key with a value of 0
and then decrements it by the specified amount.
An error occurs if the key contains a value of the wrong type or contains a string that cannot be represented as integer. DECRBY
operations are limited to 64 bit signed integers.
In Redis, the DECR
command decrements the value of a specified key by one.
If the key doesn’t exist, DECR
creates the key with a value of 0
and then decrements it by one.
An error occurs if the key contains a value of the wrong type or contains a string that cannot be represented as integer.
Continue readingIn Redis, the INCRBYFLOAT
command increments a floating point number by the specified amount. More specifically, it increments the string representing a floating point number stored at the specified key.
If the key doesn’t exist, INCRBYFLOAT
creates the key with a value of 0
and then increments it by the specified amount.
An error occurs if the key contains a value of the wrong type, or if the current key content or the specified increment are not parsable as a double precision floating point number.
Continue reading