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

fix: correctly set milliseconds ttl for set with px #180

Merged
merged 1 commit into from Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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