redis-rb icon indicating copy to clipboard operation
redis-rb copied to clipboard

Redis.current.set returns different value after 4.1.1 (in test env with fakeredis)

Open dzirtusss opened this issue 6 years ago • 1 comments

I not sure is this exactly a bug in redis-rb or fakeredis, but starting from v.4.1.1 return value was changed as following:

v.4.1.0

p Redis.current.set("aaa", "aaa")
# "OK"
p Redis.current.set("aaa", "aaa", nx: true)
# false

v.4.1.1 only in test env with fakeredis (in dev env with normal redis returns false)

p Redis.current.set("aaa", "aaa")
# "OK"
p Redis.current.set("aaa", "aaa", nx: true)
# 0

dzirtusss avatar May 08 '19 13:05 dzirtusss

  1. fakeredis#set
  2. fakeredis#write
  3. redis-rb#boolify

redis-rb 4.1.0

  BoolifySet =
    lambda { |value|
      if value && "OK" == value
        true
      else
        false
      end
    }

redis-rb 4.1.1

  BoolifySet = lambda { |value|
    case value
    when "OK"
      true
    when nil
      false
    else
      value
    end
  }

The version 4.1.1 works fine with real Redis. I'd say that fakeredis might want to adjust to real Redis reply.

https://redis.io/commands/set

Simple string reply: OK if SET was executed correctly. Null reply: a Null Bulk Reply is returned if the SET operation was not performed because the user specified the NX or XX option but the condition was not met.

$ telnet 127.0.0.1 6381
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
set foo bar
+OK
set foo bar nx
$-1

supercaracal avatar May 08 '19 15:05 supercaracal

Seems like a bug in fakeredis

byroot avatar Aug 17 '22 19:08 byroot