blob: dcd67ee036015499a511f346215fae70b8b4320e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)
}
|