Skip to content

Commit

Permalink
Put back set_with_expire that executes SET and EXPIRE in a MULTI bloc…
Browse files Browse the repository at this point in the history
…k, but with a recommendation to use #setex.
  • Loading branch information
chuyeow committed Apr 27, 2010
1 parent 4a6f7e1 commit fc68aed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/redis.rb
Expand Up @@ -333,6 +333,14 @@ def setex(key, ttl, value)
@client.call(:setex, key, ttl, value)
end

def set_with_expire(key, value, ttl)
self.class.deprecate('Redis: Use the setex method instead of set_with_expire if your version of Redis supports the SETEX command')
multi do
set(key, value)
expire(key, ttl)
end
end

def mset(*args)
@client.call(:mset, *args)
end
Expand Down
14 changes: 14 additions & 0 deletions test/redis_test.rb
Expand Up @@ -275,6 +275,20 @@ def redis.call(*attrs)
assert_equal nil, @r.get("foo")
end

test "SET with EXPIRE" do
capture_stderr do
@r.set_with_expire("bar", "s2", 1)

assert $stderr.string["Redis: Use the setex method instead of set_with_expire if your version of Redis supports the SETEX command"]

assert_equal "s2", @r.get("bar")

sleep 2

assert_equal nil, @r.get("bar")
end
end

test "GETSET" do
@r.set("foo", "bar")

Expand Down

0 comments on commit fc68aed

Please sign in to comment.