Skip to content

Instantly share code, notes, and snippets.

View fathiraz's full-sized avatar
🏠
Working from home

fathiraz arthuro fathiraz

🏠
Working from home
View GitHub Profile
@fathiraz
fathiraz / go-redis-batch-delete.md
Created December 10, 2024 08:33
Fast Redis Key Deletion in Go

Fast Redis Key Deletion in Go

I recently needed to delete millions of Redis keys in production and found that the standard approaches were too slow. Here's a solution I developed that's proven to be blazingly fast, using Go's concurrency features and Redis's UNLINK command.

Why This Matters

When working with Redis at scale, deleting keys by prefix can become a bottleneck. The naive approach of using DEL command sequentially is painfully slow. This implementation solves that by:

  • Using batch processing to reduce network calls
  • Leveraging goroutines for concurrent deletions