aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralex <[email protected]>2026-07-08 20:37:07 +0200
committeralex <[email protected]>2026-07-08 20:37:07 +0200
commit1cfae9f67a9ff7240d77ece8a2e0c54326e35c66 (patch)
tree128a96bf9fec88aa554b6b5034b2697f7914b2d1
parent880d3ae49f178e61be809fb5d2c68d5f63ea700b (diff)
downloadredis-clone-1cfae9f67a9ff7240d77ece8a2e0c54326e35c66.tar.xz
redis-clone-1cfae9f67a9ff7240d77ece8a2e0c54326e35c66.zip
removed mutex from redisDB struct and moved Execute method to shards.go file
-rw-r--r--redisDB.go9
-rw-r--r--shards.go9
2 files changed, 8 insertions, 10 deletions
diff --git a/redisDB.go b/redisDB.go
index 939fbbe..cde14d0 100644
--- a/redisDB.go
+++ b/redisDB.go
@@ -2,7 +2,6 @@ package main
import (
"fmt"
- "sync"
"time"
)
type Item struct {
@@ -11,19 +10,11 @@ type Item struct {
}
type RedisDB struct {
- mu sync.Mutex
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:
diff --git a/shards.go b/shards.go
index bd19751..cba4dd4 100644
--- a/shards.go
+++ b/shards.go
@@ -16,4 +16,11 @@ func (db *RedisDB) getShard(key string)*Shard{
val := hash.Sum64()
return db.shards[val%16]
-} \ No newline at end of file
+}
+
+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)
+}