gomodule/redigo

ERR value is not an integer or out of range

armolee opened this issue · 1 comments

Ask questions at https://stackoverflow.com/questions/ask?tags=go+redis

func init() {
	pool = &redis2.Pool{
		MaxIdle:     32,
		MaxActive:   0,
		IdleTimeout: time.Duration(120),
		Dial: func() (redis2.Conn, error) {
			return redis2.Dial(
				"tcp",
				global.RedisServer+":"+global.RedisPort,
				redis2.DialReadTimeout(time.Duration(1000)*time.Millisecond),
				redis2.DialWriteTimeout(time.Duration(1000)*time.Millisecond),
				redis2.DialConnectTimeout(time.Duration(1000)*time.Millisecond),
			)
		},
	}
}

func Set(key, value string, timeout int) (err error) {
	c := pool.Get()
	defer func() {
		_ = c.Close()
	}()
	_, err = c.Do("set", key, value, "EX", time.Duration(timeout)*time.Second)
	if err != nil {
		return errors.New(fmt.Sprintf("set %s=%s failed, err=%v", key, value, err))
	}
	return err
}

in the code:

err = Set("xxx-xxx-robot-token","at_512fd330-f287-48ae-90c9-6f2545849110", 3600)

2022/05/19 22:11:54.089 [W] [send.go:84] set robot token to redis failed, err = set xxx-xxx-robot-token=at_512fd330-f287-48ae-90c9-6f2545849110 failed, err=ERR value is not an integer or out of range

in redis cli:
image

EX value is in seconds so I suspect you want the following which also includes some style cleanups

func Set(key, value string, timeout int) error {
	c := pool.Get()
	defer c.Close()

	if _, err := c.Do("set", key, value, "EX", timeout); err != nil {
		return fmt.Errorf("set %s=%s failed, err=%w", key, value, err)
	}
	return nil
}