aboutsummaryrefslogtreecommitdiff
path: root/pkg/commands/lpop.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/commands/lpop.go')
-rw-r--r--pkg/commands/lpop.go30
1 files changed, 30 insertions, 0 deletions
diff --git a/pkg/commands/lpop.go b/pkg/commands/lpop.go
new file mode 100644
index 0000000..d1e1ccb
--- /dev/null
+++ b/pkg/commands/lpop.go
@@ -0,0 +1,30 @@
+package commands
+
+import (
+ "errors"
+ "redisClone/pkg/core"
+)
+
+func Lpop(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[0]
+ newList := 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