Skip to content

Incorrect slot calculation for Xgroup commands using Redis cluster #2982

Closed
@daviddzxy

Description

@daviddzxy

Slot calculations for Xgroup commands are incorrect. It turns out that when f.e. XGroupCreateMkStream function is called the func cmdFirstKeyPos(cmd Cmder) int function returns wrong pos number (It returns 1 instead of 2). As a result of this, the function func Slot(key string) int always receives value "create" as argument. This causes incorrectly calculated slot number. Redis will almost always respond with MOVED error and then the command will be resent to the correct node. This bug is related to issue #2978. I will try to provide PR with a fix.

Expected Behavior

Client should calculate slot for a given key correctly.

Current Behavior

Client does not calculate slot for a given key correctly.

Possible Solution

Use cmd.SetFirstKeyPos(2) in func (c cmdable) XGroupCreate(ctx context.Context, stream, group, start string) *StatusCmd and in others.

Steps to Reproduce

  1. Start redis in cluster mode
  2. Call function XGroupCreate with valid arguments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions