diff options
Diffstat (limited to 'pkg/commands/hset.go')
| -rw-r--r-- | pkg/commands/hset.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/pkg/commands/hset.go b/pkg/commands/hset.go new file mode 100644 index 0000000..33f992f --- /dev/null +++ b/pkg/commands/hset.go @@ -0,0 +1,32 @@ +package commands + +import ( + "errors" + "redisClone/pkg/core" +) + +func Hset(args []string, getShard func(k string) *core.Shard) interface{} { + if (len(args)-2)%2 != 0 { + return errors.New("wrong number of arguments for 'HSET'") + } + key := args[1] + s := getShard(key) + item, exists := s.Data[key] + var hash map[string]string + if exists { + var ok bool + hash, ok = item.Value.(map[string]string) + if !ok { + return errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") + } + } else { + hash = make(map[string]string) + } + count := 0 + for i := 2; i < len(args); i += 2 { + hash[args[i]] = args[i+1] + count++ + } + s.Data[key] = core.Item{Value: hash} + return count +} |
