0

Is there a way to delete all objects in a redis list faster then o(n) ? like the way truncate works in DB, just point the first object to null or something..

Nir
  • 2,497
  • 9
  • 42
  • 71

1 Answers1

0

NO. There's no way to make the delete operation faster than O(n), since Redis has to free resources for each item one-by-one.

However, with the UNLINK command, you can ask Redis to delete the list asynchronously, so that the delete operation won't block Redis, but delete the list in a background thread. Check this question for more info.

for_stack
  • 21,012
  • 4
  • 35
  • 48
  • Running `UNLINK` while someone else ran `UNLINK` have any effect? – Nir Oct 15 '20 at 09:30
  • 1
    Redis is single-threaded. These two UNLINK commands will be run in sequence. If these two commands unlink the same key, the second one has no effect. If unlinking two different keys, both keys will be queued for deleting asynchronously. – for_stack Oct 15 '20 at 11:13