http://grokbase.com/t/gg/redis-db/12cshy430m/how-to-delete-multiple-keys-using-python-api-and-delete-and-zrem
Both zrem and del support *args so you can pass lists to them:
keys = ('a', 'b', 'c')
r.zrem('my_key', *keys)
r.delete(*keys)
you probably want to do this in batches of a few thousands at a time, and
you can use the python slicing syntax to sent just part of the list.
suppose keys is a list of millions of rows, we can do this:
step = 1000
for idx in xrange(0, len(keys), step):
chunk = keys[idx:idx+step]
r.zrem('my_key', *chunk)
r.delete('*chunk)
Both zrem and del support *args so you can pass lists to them:
keys = ('a', 'b', 'c')
r.zrem('my_key', *keys)
r.delete(*keys)
you probably want to do this in batches of a few thousands at a time, and
you can use the python slicing syntax to sent just part of the list.
suppose keys is a list of millions of rows, we can do this:
step = 1000
for idx in xrange(0, len(keys), step):
chunk = keys[idx:idx+step]
r.zrem('my_key', *chunk)
r.delete('*chunk)
No comments:
Post a Comment