From 5f9649fe9000e4e499cffb7a1f034d8ab4bd247c Mon Sep 17 00:00:00 2001 From: alex Date: Sat, 11 Jul 2026 12:58:05 +0200 Subject: refactored more commands to work with command registry --- pkg/commands/rpop.go | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 pkg/commands/rpop.go (limited to 'pkg/commands/rpop.go') diff --git a/pkg/commands/rpop.go b/pkg/commands/rpop.go new file mode 100644 index 0000000..4ef4a1d --- /dev/null +++ b/pkg/commands/rpop.go @@ -0,0 +1,30 @@ +package commands + +import ( + "errors" + "redisClone/pkg/core" +) + +func Rpop(args []string, getShard func(k string) *core.Shard) interface{}{ + key := args[1] + s := getShard(key) + item, exists := s.Data[key] + if !exists { + return nil + } + typedList, ok := item.Value.([]string) + if !ok { + return errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") + } + if len(typedList) == 0 { + return nil + } + newItem := typedList[len(typedList)-1] + newList := typedList[:len(typedList)-1] + if len(newList) <= 0 { + delete(s.Data, key) + } else { + s.Data[key] = core.Item{Value: newList} + } + return newItem +} \ No newline at end of file -- cgit v1.2.3