diff options
| author | alex <[email protected]> | 2026-07-08 20:41:39 +0200 |
|---|---|---|
| committer | alex <[email protected]> | 2026-07-08 20:41:39 +0200 |
| commit | 2d2b8102ecc5b6a786a97c6c0fc49737c9088e63 (patch) | |
| tree | 1d8e6d18ebf3bb5528ef5f1725e63dd77f7eedc3 | |
| parent | 1cfae9f67a9ff7240d77ece8a2e0c54326e35c66 (diff) | |
| download | redis-clone-2d2b8102ecc5b6a786a97c6c0fc49737c9088e63.tar.xz redis-clone-2d2b8102ecc5b6a786a97c6c0fc49737c9088e63.zip | |
made NumShards a global const
| -rw-r--r-- | main.go | 6 | ||||
| -rw-r--r-- | shards.go | 2 |
2 files changed, 4 insertions, 4 deletions
@@ -9,6 +9,7 @@ import ( "strings" ) +const NumShards = 16 var db RedisDB @@ -41,10 +42,9 @@ var commandRegistry = map[string]handlerFunc{ } func main() { - numShards := 16 - shards := make([]*Shard, numShards) + shards := make([]*Shard, NumShards) - for i := 0; i < numShards; i++ { + for i := 0; i < NumShards; i++ { shards[i] = &Shard{ data: make(map[string]Item), id: i, @@ -15,7 +15,7 @@ func (db *RedisDB) getShard(key string)*Shard{ hash.Write([]byte(key)) val := hash.Sum64() - return db.shards[val%16] + return db.shards[val%NumShards] } func (db *RedisDB) Execute(key string, fn func(*Shard) interface{}) interface{} { |
