diff options
| author | alex <[email protected]> | 2026-07-08 20:30:16 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-08 20:30:16 +0200 |
| commit | 513e5e7961ecc9fe8155811d6cbb6a6c77e0638d (patch) | |
| tree | 49a3aea7e17040b95fd54d322db8a5284933ca1a /redisDB.go | |
| parent | b523e77159b89cdb22a8e6e7f9d0046cd4269443 (diff) | |
| download | redis-clone-513e5e7961ecc9fe8155811d6cbb6a6c77e0638d.tar.xz redis-clone-513e5e7961ecc9fe8155811d6cbb6a6c77e0638d.zip | |
refactored EXISTS,SET,GET to support multiple shards
Diffstat (limited to 'redisDB.go')
| -rw-r--r-- | redisDB.go | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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: |
