Fix “One or more scores can’t be converted into double” when using SORT or SORT_RO in Redis

If you’re getting an error that reads “One or more scores can’t be converted into double” when using either the SORT or SORT_RO commands in Redis, it could be because you omitted the ALPHA modifier when trying to sort string values.

If you want to sort string values lexicographically, you need to use the ALPHA modifier when using the SORT or SORT_RO command.

Example of Error

Here’s an example of code that causes the error:

SORT cats

Result:

(error) ERR One or more scores can't be converted into double

Here, I am trying to sort a set called cats that contains the names of cats, but I am getting an error.

Here’s what the set contains:

SMEMBERS cats

Result:

1) "Meow"
2) "Scratch"
3) "Fluffy"

So each member is a string value containing the name of a cat.

Solution

As mentioned, if we want to sort string values lexicographically, we need to use the ALPHA modifier when using the SORT or SORT_RO command:

SORT cats ALPHA

Result:

1) "Fluffy"
2) "Meow"
3) "Scratch"

So, all we needed to do to fix the problem was add ALPHA to our code.

The same applies to the SORT_RO command, which is basically a read-only variant of SORT.