aboutsummaryrefslogtreecommitdiff
path: root/shards.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 /shards.go
parentb523e77159b89cdb22a8e6e7f9d0046cd4269443 (diff)
downloadredis-clone-513e5e7961ecc9fe8155811d6cbb6a6c77e0638d.tar.xz
redis-clone-513e5e7961ecc9fe8155811d6cbb6a6c77e0638d.zip
refactored EXISTS,SET,GET to support multiple shards
Diffstat (limited to 'shards.go')
-rw-r--r--shards.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/shards.go b/shards.go
new file mode 100644
index 0000000..55ab976
--- /dev/null
+++ b/shards.go
@@ -0,0 +1,18 @@
+package main
+
+import (
+ "hash/fnv"
+ "sync"
+)
+type Shard struct{
+ mu sync.Mutex
+ data map[string]Item
+}
+
+func (db *RedisDB) getShard(key string)*Shard{
+ hash := fnv.New64a()
+ hash.Write([]byte(key))
+ val := hash.Sum64()
+
+ return db.shards[val%16]
+} \ No newline at end of file