go-redis/redis_rate

v is nil,occured pannic error

busyfree opened this issue · 1 comments

https://github.com/go-redis/redis_rate/blob/8eadf45ee4d9d7a53189c2a968ead40521a76322/rate.go#L107C28-L107C28
use allowN.Eval replace the allowN.Run then test is ok.

values := []interface{}{limit.Burst, limit.Rate, limit.Period.Seconds(), n}
	// v, err := allowN.Run(ctx, l.rdb, []string{redisPrefix + key}, values...).Result()
	v, err := allowN.Eval(ctx, l.rdb, []string{redisPrefix + key}, values...).Result()
	if err != nil {
		return nil, err
	}
	values = v.([]interface{})
github.com/redis/go-redis/v9 script.go
// Run optimistically uses EVALSHA to run the script. If script does not exist
// it is retried using EVAL.
func (s *Script) Run(ctx context.Context, c Scripter, keys []string, args ...interface{}) *Cmd {
	r := s.EvalSha(ctx, c, keys, args...)
	if HasErrorPrefix(r.Err(), "NOSCRIPT") { // maybe here have bug?
		return s.Eval(ctx, c, keys, args...)
	}
	return r
}

test evalsha in aliyun redis cluster mode, the script return error msg is (error) NOSCRIPT No matching script. Please use EVAL. so the code if HasErrorPrefix(r.Err(), "NOSCRIPT") { have a bug is error not start with NOSCRIPT.