Skip to content

Scan command in pipeline cause infinite loop #2811

@a791446794

Description

@a791446794

Scan command in pipeline cause infinite loop

Expected Behavior

Scan command return an iterator, then invoke iterator.Next(ctx) should forward scan cursor.

Current Behavior

block at iterator.Next()

Possible Solution

Steps to Reproduce

        ctx := context.Background()
	var cmd *redis.ScanCmd
	cmds, err := rdb.Pipelined(ctx, func(pipeliner redis.Pipeliner) error {
		_ = pipeliner.Scan(ctx, 0, "som:key:*", 1000)
		return nil
	})
	cmd = cmds[0].(*redis.ScanCmd)
	if err != nil {
		t.Error(cmd.Err())
		return
	}
	var cnt = 1
	iter := cmd.Iterator()
	var keys []string
	for {
		val := iter.Val()
		if val != "" {
			keys = append(keys, val)
		}
		if !iter.Next(ctx) { // infinite loop here
			break
		}
		if iter.Err() != nil {
			t.Error(iter.Err())
			return
		}
		cnt++
	}
	t.Logf("cnt:%d,result, len(%d):\n%s", cnt, len(keys), strings.Join(keys, "\n"))

Context (Environment)

redis/v9

Detailed Description

Possible Implementation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions