Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update message.go #570

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -723,26 +723,36 @@ func (m *RedisMessage) AsStrSlice() ([]string, error) {
return s, nil
}

// AsIntSlice check if message is a redis array/set response, and convert to []int64.
// redis nil element and other non integer element will be present as zero.
func (m *RedisMessage) AsIntSlice() ([]int64, error) {
values, err := m.ToArray()
if err != nil {
return nil, err
}
s := make([]int64, len(values))
for i, v := range values {
if len(v.string) != 0 {
if s[i], err = strconv.ParseInt(v.string, 10, 64); err != nil {
return nil, err
}
} else {
s[i] = v.integer
}
}
return s, nil
// AsIntSlice checks if the message is a Redis array/set response and converts it to []int64.
// Redis nil elements and other non-integer elements will be present as zero.
func (r RedisResult) AsIntSlice() ([]int64, error) {
Copy link
Contributor

@SoulPancake SoulPancake Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of this? @neelpatel04466

if r.err != nil {
return nil, r.err
}

if r.val == nil {
return nil, fmt.Errorf("nil RedisMessage value")
}

values, err := r.val.ToArray()
if err != nil {
return nil, err
}

s := make([]int64, len(values))
for i, v := range values {
if len(v.string) != 0 {
if s[i], err = strconv.ParseInt(v.string, 10, 64); err != nil {
return nil, err
}
} else {
s[i] = v.integer
}
}
return s, nil
}


// AsFloatSlice check if message is a redis array/set response, and convert to []float64.
// redis nil element and other non float element will be present as zero.
func (m *RedisMessage) AsFloatSlice() ([]float64, error) {
Expand Down