From 6aebb5bb1d35016bc8e3bed04e971614898cb6ff Mon Sep 17 00:00:00 2001 From: alex Date: Thu, 9 Jul 2026 16:26:00 +0200 Subject: refactored FLUSHALL to work with shards added ExecuteAll and ExecuteReadAll methods to the db --- shards.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'shards.go') diff --git a/shards.go b/shards.go index 279d9b1..ef9f9ef 100644 --- a/shards.go +++ b/shards.go @@ -65,3 +65,31 @@ func ( db *RedisDB) ExecuteMulti(keys []string, fn func([]*Shard) interface{})in return fn(shards) } } + +func ( db *RedisDB) ExecuteAll(fn func([]*Shard) interface{})interface{}{ + for _, shard := range db.shards { + shard.mu.Lock() + } + + defer func(){ + for i := len(db.shards)-1;i >= 0; i --{ + db.shards[i].mu.Unlock() + } + }() + + return fn(db.shards) +} + +func ( db *RedisDB) ExecuteReadAll(fn func([]*Shard) interface{})interface{}{ + for _, shard := range db.shards { + shard.mu.RLock() + } + + defer func(){ + for i := len(db.shards)-1;i >= 0; i --{ + db.shards[i].mu.RUnlock() + } + }() + + return fn(db.shards) +} \ No newline at end of file -- cgit v1.2.3