Could I change redis data structure list to set -
i used redis list structure store data, want change list type set. command this?
no built-in way that. need manually items list , insert set. if list small, can use following lua script:
repeat local item = redis.call('lpop', keys[1]) if (item) redis.call('sadd', keys[2], item) end until not item
however, if list large, script block redis long time. have incrementally move items list set:
- call
lrange
items (small batch) list - call
sadd
insert these items set - call
ltrim
remove these items list - go step 1 until items have been moved.
Comments
Post a Comment