aboutsummaryrefslogtreecommitdiff
path: root/redisDB.go
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-08 20:30:16 +0200
committeralex <[email protected]>2026-07-08 20:30:16 +0200
commit513e5e7961ecc9fe8155811d6cbb6a6c77e0638d (patch)
tree49a3aea7e17040b95fd54d322db8a5284933ca1a /redisDB.go
parentb523e77159b89cdb22a8e6e7f9d0046cd4269443 (diff)
downloadredis-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.go10
1 files changed, 9 insertions, 1 deletions
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: