aboutsummaryrefslogtreecommitdiff
path: root/shards.go
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-09 16:26:00 +0200
committeralex <[email protected]>2026-07-09 16:26:00 +0200
commit6aebb5bb1d35016bc8e3bed04e971614898cb6ff (patch)
tree0b0d8be7a30486b79459295f1fe729e5d512747f /shards.go
parent78ee0c69fdc9d328ab3e3048f0207957c4e48454 (diff)
downloadredis-clone-6aebb5bb1d35016bc8e3bed04e971614898cb6ff.tar.xz
redis-clone-6aebb5bb1d35016bc8e3bed04e971614898cb6ff.zip
refactored FLUSHALL to work with shards added ExecuteAll and ExecuteReadAll methods to the db
Diffstat (limited to 'shards.go')
-rw-r--r--shards.go28
1 files changed, 28 insertions, 0 deletions
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