Fix “WRONGTYPE Operation against a key holding the wrong kind of value” when using SMEMBERS in Redis

If you get an error that reads “WRONGTYPE Operation against a key holding the wrong kind of value” when using the SMEMBERS command in Redis, it’s probably because you’re passing a key with the wrong data type to the command.

The SMEMBERS command is a “set” command, and so it is intended to be used on keys that contain a set. If the key holds a different data type, you’ll likely get the above error.

Continue reading

Redis HSETNX Command

In Redis, the HSETNX command enables us to set a field in a hash, but only if the field doesn’t already exist. It sets the field at the specified key to the value we provide.

If the key doesn’t exist, it’s created with the specified hash value. If the field already exists, nothing is set (i.e. the command has no effect).

Continue reading