package commands import ( "errors" "redisClone/pkg/core" "strconv" "time" ) func Lrange(args []string, getShard func(k string) *core.Shard) interface{}{ start, err1 := strconv.Atoi(args[2]) stop, err2 := strconv.Atoi(args[3]) if err1 != nil || err2 != nil { err := errors.New("value is not an integer or out of range") return err } key := args[1] s := getShard(key) item, exists := s.Data[key] if !exists { return []string{} } if item.ExpiresAt != nil && time.Now().After(*item.ExpiresAt) { delete(s.Data, key) return nil } typedList, ok := item.Value.([]string) if !ok { return errors.New("WRONGTYPE Operation against a key holding the wrong kind of value") } size := len(typedList) if start < 0 { start += size if start < 0 { start = 0 } } if stop < 0 { stop += size if stop < 0 { stop = 0 } } if stop >= size { stop = size - 1 } if start > stop || start >= size { return []string{} } return typedList[start : stop+1] }