How to copy data from hash to sorted set

36 views
Skip to first unread message

Ankit Gupta

unread,
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. 

Thanks,
Ankit

Ankit Gupta

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

We are using redis version 5.0.5

Greg Andrews

unread,
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

unread,
Oct 18, 2021, 11:28:09 AMOct 18
to redi...@googlegroups.com
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 redis-db+u...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/redis-db/b56b646c-c8ad-46b8-9691-33e158549dfbn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages