How to copy data from hash to sorted set

78 views
Skip to first unread message

Ankit Gupta

unread,
Oct 13, 2021, 12:13:09 PM10/13/21
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 PM10/13/21
to Redis DB

We are using redis version 5.0.5

Greg Andrews

unread,
Oct 17, 2021, 2:06:21 AM10/17/21
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 AM10/18/21
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