Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem about overflow inspection of INCRBY/DECRBY #291

Closed
z4deepfz opened this issue Aug 23, 2022 · 1 comment · Fixed by #361
Closed

Problem about overflow inspection of INCRBY/DECRBY #291

z4deepfz opened this issue Aug 23, 2022 · 1 comment · Fixed by #361

Comments

@z4deepfz
Copy link

z4deepfz commented Aug 23, 2022

Miniredis throws out no error of overflowing when the value becomes greater than math.MaxInt64 after INCRBY or DECRBY (also INCR or DECR). Instead it returns a negative number which was exactly the overflowed value. As a comparison, the real redis instance returns ERR increment or decrement would overflow which thrown out by overflow detection and nothing will be changed.

I found the cause of it and some potential issues as well. I can make a patch to it if it is indeed an unexpected behavior of miniredis.

The following code reproduces the problem.

package main

import(
    "log"
    "math"
    "github.com/alicebob/miniredis/v2"
    "github.com/gomodule/resign/redis"
)

func main() {
    server, _ := miniredis.Run()
    minirds, _ := redis.Dial("tcp", server.Addr())
    defer miniredis.Close()
    realrds, _ := redis.Dial("tcp", "127.0.0.1:6379") // redis instance
    defer realrds.Close()
    overflowTest(minirds)
    overflowTest(realrds)
}

func overflowTest(r redis.Conn) {
    _, _ = r.Do("SET", "number", 100)
    rsp, err := redis.Int64(r.Do("INCRBY", "number", math.MaxInt64)
    if err != nil {
        log.Printf("got an error when exec INCRBY, err=%v", err)
    }
    log.Printf("got=%d", rsp)
}
@z4deepfz z4deepfz changed the title Problem of overflow inspection of INCRBY/DECRBY Problem about overflow inspection of INCRBY/DECRBY Aug 25, 2022
@alicebob
Copy link
Owner

alicebob commented Oct 11, 2022 via email

wszaranski added a commit to wszaranski/miniredis that referenced this issue Mar 15, 2024
Fixes INCR, DECR, INCRBY, DECRBY overflow to return proper error
message.

Closes: alicebob#291

Signed-off-by: Wojciech Szarański <wojciech.szaranski@gmail.com>
wszaranski added a commit to wszaranski/miniredis that referenced this issue Mar 15, 2024
Fixes INCR, DECR, INCRBY, DECRBY to return proper message when value
would overflow.

Closes: alicebob#291

Signed-off-by: Wojciech Szarański <wojciech.szaranski@gmail.com>
wszaranski added a commit to wszaranski/miniredis that referenced this issue Mar 15, 2024
Fixes INCR, DECR, INCRBY, DECRBY to return error when value would
overflow.

Closes: alicebob#291

Signed-off-by: Wojciech Szarański <wojciech.szaranski@gmail.com>
alicebob pushed a commit that referenced this issue Mar 23, 2024
Fixes INCR, DECR, INCRBY, DECRBY to return error when value would
overflow.

Closes: #291

Signed-off-by: Wojciech Szarański <wojciech.szaranski@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants