diff options
| author | alex <[email protected]> | 2026-07-09 16:26:00 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-09 16:26:00 +0200 |
| commit | 6aebb5bb1d35016bc8e3bed04e971614898cb6ff (patch) | |
| tree | 0b0d8be7a30486b79459295f1fe729e5d512747f /shards.go | |
| parent | 78ee0c69fdc9d328ab3e3048f0207957c4e48454 (diff) | |
| download | redis-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.go | 28 |
1 files changed, 28 insertions, 0 deletions
@@ -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 |
