From 56bf3fc1b36e7301727e9d8d94a6239a88c4e208 Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 11 Jul 2026 13:18:25 +0200 Subject: refactroed LPUSH and RPUSH for command registry --- pkg/commands/lpush.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 pkg/commands/lpush.go (limited to 'pkg/commands/lpush.go') diff --git a/pkg/commands/lpush.go b/pkg/commands/lpush.go new file mode 100644 index 0000000..dcd67ee --- /dev/null +++ b/pkg/commands/lpush.go @@ -0,0 +1,26 @@ +package commands + +import ( + "errors" + "redisClone/pkg/core" +) + +func Lpush(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(newItems, list...) + s.Data[key] = core.Item{Value: list} + return len(list) +} \ No newline at end of file -- cgit v1.2.3