Skip to content

Instantly share code, notes, and snippets.

@the-reverend
Last active December 11, 2015 06:28
Show Gist options
  • Save the-reverend/4559176 to your computer and use it in GitHub Desktop.
Save the-reverend/4559176 to your computer and use it in GitHub Desktop.
delete all records from a riak bucket
import sys
import riak
import time
def time_it(func):
start_time = time.time()
result = func()
return (result, time.time() - start_time)
def deletebucket():
if len(keys) > 0:
for count, key in enumerate(keys):
if count % 100 == 0:
print "%d records" % count
o = bucket.get(key)
o.delete()
return (count + 1)
else:
return 0
if len(sys.argv) < 4:
print 'usage: {0} riak_host riak_pb_port bucket_name'.format(sys.argv[0])
exit()
riak_host = sys.argv[1]
riak_port = sys.argv[2]
bucket_name = sys.argv[3]
client = riak.RiakClient(host=riak_host, port=int(riak_port), transport_class=riak.RiakPbcTransport)
bucket = client.bucket(bucket_name)
keys = bucket.get_keys()
yes = raw_input('Are you sure you want to delete {0} records from riak/{1}? (write Yes):'.format(len(keys),bucket_name))
assert yes == 'Yes'
if __name__ == '__main__':
print "%d records in %.3f seconds" % time_it(deletebucket)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment