Easy way to delete all keys in a namespace

Hi,

I am using a test namespace for unit test. Before the test start, I’d like to clear all keys in the namespace so that I get a clean db for testing. But I couldn’t find an API to do that. Do I have to delete every set/key one by one?

Thanks.

Ming

No built in method, scan with delete in loop should do the trick.

1 Like

Thanks for the prompt reply.

FYI I figured to use Client.ExecuteUDF() with a statement only specify namespace, calling a UDF that simply call aerospike:remove(rec). It seems work. But the execution is slow even for nearly empty db …

A Record UDF operate on a single record but you can pass in an entire set or secondary index for it to operate on all the keys.

If you’re just calling a record UDF, it’s no different than just doing a scan + delete loop through the client itself. This performance depends on network latency, async vs synchronous calls, number of threads, cpu speed, etc.

Aren’t stream udf’s read only ?

Yes, updated the post. A simple record UDF with aerospike:remove(rec) statement inside can operate on all the records in a set or with a secondary index filter and delete the records quickly on the server side.

This still wont be instant, the performance will depend on current transaction load, lua threads, ram/disk access speed, cluster size, potential migrations, etc.

1 Like

For testing purposes, using a random and long set name can also do the trick.