diff options
Diffstat (limited to 'pkg/commands/rpush.go')
| -rw-r--r-- | pkg/commands/rpush.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/pkg/commands/rpush.go b/pkg/commands/rpush.go new file mode 100644 index 0000000..ea7e691 --- /dev/null +++ b/pkg/commands/rpush.go @@ -0,0 +1,26 @@ +package commands + +import ( + "errors" + "redisClone/pkg/core" +) + +func Rpush(args []string, getShard func(k string) *core.Shard) interface{}{ + key := args[1] + newItems := args[2:] + s := getShard(key) + var list []string + existingItem, exists := s.Data[key] + if exists { + var ok bool + list, ok = existingItem.Value.([]string) + if !ok { + return errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") + } + } else { + list = []string{} + } + list = append(list, newItems...) + s.Data[key] = core.Item{Value: list} + return len(list) +}
\ No newline at end of file |
