From 513e5e7961ecc9fe8155811d6cbb6a6c77e0638d Mon Sep 17 00:00:00 2001 From: alex Date: Wed, 8 Jul 2026 20:30:16 +0200 Subject: refactored EXISTS,SET,GET to support multiple shards --- redisDB.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'redisDB.go') diff --git a/redisDB.go b/redisDB.go index 74a7de6..939fbbe 100644 --- a/redisDB.go +++ b/redisDB.go @@ -9,13 +9,21 @@ type Item struct { Value any ExpiresAt *time.Time } + type RedisDB struct { mu sync.Mutex - data map[string]Item + shards []*Shard } type SimpleString string +func (db *RedisDB) Execute(key string, fn func(*Shard) interface{}) interface{} { + shard := db.getShard(key) + shard.mu.Lock() + defer shard.mu.Unlock() + return fn(shard) +} + func serializeRESP(v any) []byte { switch val := v.(type) { case string: -- cgit v1.2.3