How to copy data from hash to sorted set

Skip to first unread message

Ankit Gupta

Oct 13, 2021, 12:13:09 PMOct 13
to Redis DB
Hi Experts,

We are moving our metadata from hash to sorted set to support expiry of fields in hash.

We wanted to understand if there's any easy way/command to copy data between these 2 different data-structures. 


Ankit Gupta

Oct 13, 2021, 12:18:18 PMOct 13
to Redis DB

We are using redis version 5.0.5

Greg Andrews

Oct 17, 2021, 2:06:21 AMOct 17
to Redis DB
Redis doesn't have a built-in conversion command from a hash to a sorted set, so you'll have to write a script to do that.  I imagine you'll have to change your client code to handle the different commands for reading/writing a sorted set rather than a hash, so you'll already be coordinating an explicit change and not trying to change the hashes while clients are actively using them.  So a script to convert each hash -> sorted-set ought to be fairly simple.

Ankit Gupta

Oct 18, 2021, 11:28:09 AMOct 18
Thank you for the reply Greg.
Thanks & Regards,
Ankit Gupta
+91 965 427 1456
> --
> You received this message because you are subscribed to the Google Groups "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> To view this discussion on the web visit
Reply all
Reply to author
0 new messages