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

fix(redis): fix timeout error #777

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
26 changes: 18 additions & 8 deletions v1/backends/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,25 @@ func (b *Backend) getGroupMeta(conn redis.Conn, groupUUID string) (*tasks.GroupM
func (b *Backend) getStates(conn redis.Conn, taskUUIDs ...string) ([]*tasks.TaskState, error) {
taskStates := make([]*tasks.TaskState, len(taskUUIDs))

var reply []interface{}
// conn.Do requires []interface{}... can't pass []string unfortunately
taskUUIDInterfaces := make([]interface{}, len(taskUUIDs))
for i, taskUUID := range taskUUIDs {
taskUUIDInterfaces[i] = interface{}(taskUUID)
}

reply, err := redis.Values(conn.Do("MGET", taskUUIDInterfaces...))
if err != nil {
return taskStates, err
stepCount := 20
uuidCursor := 0
for uuidCursor < len(taskUUIDs) {
startIdx := uuidCursor
uuidCursor = uuidCursor + stepCount
if uuidCursor > len(taskUUIDs) {
uuidCursor = len(taskUUIDs)
}
taskUUIDInterfaces := make([]interface{}, uuidCursor-startIdx)
for i, taskUUID := range taskUUIDs[startIdx:uuidCursor] {
taskUUIDInterfaces[i] = interface{}(taskUUID)
}
values, err := redis.Values(conn.Do("MGET", taskUUIDInterfaces...))
if err != nil {
return taskStates, err
}
reply = append(reply, values...)
}

for i, value := range reply {
Expand Down
26 changes: 18 additions & 8 deletions v2/backends/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,25 @@ func (b *Backend) getGroupMeta(conn redis.Conn, groupUUID string) (*tasks.GroupM
func (b *Backend) getStates(conn redis.Conn, taskUUIDs ...string) ([]*tasks.TaskState, error) {
taskStates := make([]*tasks.TaskState, len(taskUUIDs))

var reply []interface{}
// conn.Do requires []interface{}... can't pass []string unfortunately
taskUUIDInterfaces := make([]interface{}, len(taskUUIDs))
for i, taskUUID := range taskUUIDs {
taskUUIDInterfaces[i] = interface{}(taskUUID)
}

reply, err := redis.Values(conn.Do("MGET", taskUUIDInterfaces...))
if err != nil {
return taskStates, err
stepCount := 20
uuidCursor := 0
for uuidCursor < len(taskUUIDs) {
startIdx := uuidCursor
uuidCursor = uuidCursor + stepCount
if uuidCursor > len(taskUUIDs) {
uuidCursor = len(taskUUIDs)
}
taskUUIDInterfaces := make([]interface{}, uuidCursor-startIdx)
for i, taskUUID := range taskUUIDs[startIdx:uuidCursor] {
taskUUIDInterfaces[i] = interface{}(taskUUID)
}
values, err := redis.Values(conn.Do("MGET", taskUUIDInterfaces...))
if err != nil {
return taskStates, err
}
reply = append(reply, values...)
}

for i, value := range reply {
Expand Down