go-redis/redis · error

redis: command %T does not have SetVal method

Error message

redis: command %T does not have SetVal method

What it means

Error "redis: command %T does not have SetVal method" thrown in go-redis/redis.

Source

Thrown at osscluster_router.go:979

		}
	default:
		// Fallback to reflection for unknown types
		return c.setCommandValueReflection(cmd, value)
	}

	return nil
}

// setCommandValueReflection is a fallback function that uses reflection
func (c *ClusterClient) setCommandValueReflection(cmd Cmder, value interface{}) error {
	cmdValue := reflect.ValueOf(cmd)
	if cmdValue.Kind() != reflect.Ptr || cmdValue.IsNil() {
		return errInvalidCmdPointer
	}

	setValMethod := cmdValue.MethodByName("SetVal")
	if !setValMethod.IsValid() {
		return fmt.Errorf("redis: command %T does not have SetVal method", cmd)
	}

	args := []reflect.Value{reflect.ValueOf(value)}

	switch cmd.(type) {
	case *XAutoClaimCmd, *XAutoClaimJustIDCmd:
		args = append(args, reflect.ValueOf(""))
	case *ScanCmd:
		args = append(args, reflect.ValueOf(uint64(0)))
	case *KeyValuesCmd, *ZSliceWithKeyCmd:
		if key, ok := value.(string); ok {
			args = []reflect.Value{reflect.ValueOf(key)}
			if _, ok := cmd.(*ZSliceWithKeyCmd); ok {
				args = append(args, reflect.ValueOf([]Z{}))
			} else {
				args = append(args, reflect.ValueOf([]string{}))
			}
		}

View on GitHub (pinned to 36d97525cd)

Solutions

  1. Implement SetVal on the custom Cmder type (required by the customvet setval rule)
  2. Use the built-in command types that already implement SetVal

When it happens

Trigger: Thrown at osscluster_router.go:979 when the library encounters an invalid state.

Common situations: Run the repo's custom vet tool to catch Cmder types missing SetVal at build time.


AI-assisted analysis of go-redis/redis@36d97525cd (2026-08-06). Data as JSON: /data/errors/0ef2f1a46d7e04e4.json. Report an issue: GitHub.