Search code examples
redishigh-load

Best way to delete members of one set from multiple other sets


Let say I have a community with 50 000 members. So there are one Redis set called community_###_members with 50 000 sha1 keys of users and for each user his own set user_###_communities exists with sha1 hash of community above

In some time I decide to delete community.. What is the best algorithm to kill all members?

Thanks.


Solution

  • assuming you really want to actually delete members of a community that does not exist, it's something like (python code example):

    memebrs = redis.smembers('community_members')
    pipe = redis.pipeline()
    pipe.delete('community_memebrs')
    for member in members:
       pipe.delete(member)
    pipe.execute()
    

    if the community is very large you might want to do that N memebrs at a time, so the server will not stall until you finish all.