If you ever find yourself in the situation where you need to get a random key when using Redis, take a look at the RANDOMKEY
command.
This command returns a random key from the currently selected database.
Continue readingIf you ever find yourself in the situation where you need to get a random key when using Redis, take a look at the RANDOMKEY
command.
This command returns a random key from the currently selected database.
Continue readingRedis provides a couple of commands that allow us to sort the elements in a list, set, or sorted set.
The SORT
command is probably the most obvious, and does exactly what its namesake promises. However, there’s also a SORT_RO
command, which is a read-only variant of the SORT
command.
There are a couple of commands that enable us to rename a key in Redis. The one we use will depend on whether or not we want to overwrite any existing keys.
Continue readingIf you’re getting an error that reads “ERR syntax error” in Redis, it could be because you’re calling the SPOP
command with too many arguments.
At the time of writing, I find that I only get this argument when I pass too many arguments. If I pass no arguments, I get a different error.
Continue readingIf we have a key that holds a string value, we can use the GETRANGE
command to get a substring from that value.
Redis also has a SUBSTR
command that does the same thing, but that was deprecated in Redis 2.0.0, in favour of the GETRANGE
command.
As from Redis 6.2.0, we can use the COPY
command whenever we need to copy a key’s value to another key.
If you’re getting an error that reads “ERR wrong number of arguments for ‘spop’ command” in Redis, it’s because you’re calling the SPOP
command with the wrong number of arguments.
At the time of writing, I find that I only get this argument when I pass no arguments. If I pass too many, I get a different error.
In any case, to fix this issue, be sure to pass at least one argument to the command (and at the time of writing, no more than two).
Continue readingHere are a couple of ways to check whether or not a key exists in Redis.
Continue readingRedis provides us with two commands that allow us to get one or more random members from a given set – SRANDMEMBER
and SPOP
.
Actually, the commands are slightly different in that one deletes the random member whereas the other doesn’t, and so the command you choose will depend on whether or not you want to delete the random member at the same time.
Continue readingIf you’re getting an error that reads “ERR value is out of range, must be positive” in Redis, it’s probably because you’re passing a negative count value to the SPOP
command.
To fix this issue, make sure the second argument (if supplied) is a positive value.
Continue reading