Skip to content

Commit

Permalink
fix: correctly set milliseconds ttl for set with px (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanMertz committed Apr 6, 2020
1 parent 5ef8f8b commit e7cef50
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/mock_redis/string_methods.rb
Expand Up @@ -233,7 +233,7 @@ def set(key, value, options = {})
if duration == 0
raise Redis::CommandError, 'ERR invalid expire time in set'
end
expire(key, duration / 1000.0)
pexpire(key, duration)
end

return_true ? true : 'OK'
Expand Down
6 changes: 4 additions & 2 deletions spec/commands/set_spec.rb
Expand Up @@ -59,9 +59,11 @@

it 'accepts PX milliseconds' do
key = 'mock-redis-test'
@mock.set(key, 1, px: 1000).should == 'OK'
@mock.set(key, 1, px: 500).should == 'OK'
@mock.get(key).should_not be_nil
Time.stub(:now).and_return(@now + 2)
Time.stub(:now).and_return(@now + 300 / 1000.to_f)
@mock.get(key).should_not be_nil
Time.stub(:now).and_return(@now + 600 / 1000.to_f)
@mock.get(key).should be_nil
end
end
Expand Down

0 comments on commit e7cef50

Please sign in to comment.