I decided to compile a list of commands that can be used to get the string value from a key in Redis. These are all string commands – commands that can be used when working with strings. In other words, the assumption is that the key holds a string value.
Continue readingFix “WRONGTYPE Operation against a key holding the wrong kind of value” When Calling SUNION or SUNIONSTORE in Redis
If you’re getting an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when calling either the SUNION
command or the SUNIONSTORE
command in Redis, it’s probably because you’re passing a key with the wrong data type.
To fix this issue, make sure that each key that you pass holds a set.
Continue reading3 Ways to Return all Members of a Set in Redis
When working with Redis, we have multiple ways to return the members of a set. Here are 3 ways to return the members of a set in Redis.
Continue readingHow to Get a Key’s Type in Redis
If you know the name of a key in Redis, but you want to find out it’s type (eg, string, list, hash, set, etc), look no further than the TYPE
command. This command returns the string representation of the type of the value at the given key.
How to Return a Random Key in Redis
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 reading2 Ways to Sort the Elements in a Redis List, Set, or Sorted Set
Redis 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.
Add Minutes to a Time Value in PostgreSQL
In PostgreSQL, we can use the +
operator to add one or more minutes to a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also add minutes to a date
value or a date
and time
combination.
2 Ways to Rename a Key in Redis
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 readingFix: “ERR syntax error” when using SPOP in Redis
If 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 readingHow to Get a Substring in Redis
If 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.