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 hmset exception and xadd spec errors #206

Merged
merged 1 commit into from Mar 2, 2021
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/hash_methods.rb
Expand Up @@ -94,7 +94,7 @@ def hmset(key, *kvpairs)
assert_has_args(kvpairs, 'hmset')

if kvpairs.length.odd?
raise Redis::CommandError, err_msg || 'ERR wrong number of arguments for HMSET'
raise Redis::CommandError, err_msg || 'ERR wrong number of arguments for \'hmset\' command'
end

kvpairs.each_slice(2) do |(k, v)|
Expand Down
12 changes: 6 additions & 6 deletions spec/commands/xadd_spec.rb
Expand Up @@ -14,20 +14,20 @@

it 'returns an id based on the timestamp' do
t = Time.now.to_i
id = @redises.xadd(@key, key: 'value')
expect(@redises.xadd(@key, key: 'value')).to match(/#{t}\d{3}-0/)
id = @redises.xadd(@key, { key: 'value' })
expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}\d{3}-0/)
end

it 'adds data with symbols' do
@redises.xadd(@key, symbol_key: :symbol_value)
@redises.xadd(@key, { symbol_key: :symbol_value })
expect(@redises.xrange(@key, '-', '+').last[1])
.to eq('symbol_key' => 'symbol_value')
end

it 'increments the sequence number with the same timestamp' do
Timecop.freeze do
@redises.xadd(@key, key: 'value')
expect(@redises.xadd(@key, key: 'value')).to match(/\d+-1/)
@redises.xadd(@key, { key: 'value' })
expect(@redises.xadd(@key, { key: 'value' })).to match(/\d+-1/)
end
end

Expand Down Expand Up @@ -67,7 +67,7 @@
it 'caters for the current time being before the last time' do
t = (Time.now.to_f * 1000).to_i + 2000
@redises.xadd(@key, { key: 'value' }, id: "#{t}-0")
expect(@redises.xadd(@key, key: 'value')).to match(/#{t}-1/)
expect(@redises.xadd(@key, { key: 'value' })).to match(/#{t}-1/)
end

it 'appends a sequence number if it is missing' do
Expand Down
4 changes: 2 additions & 2 deletions spec/commands/xlen_spec.rb
Expand Up @@ -14,9 +14,9 @@

it 'returns the number of items in the stream' do
expect(@redises.xlen(@key)).to eq 0
@redises.xadd(@key, key: 'value')
@redises.xadd(@key, { key: 'value' })
expect(@redises.xlen(@key)).to eq 1
3.times { @redises.xadd(@key, key: 'value') }
3.times { @redises.xadd(@key, { key: 'value' }) }
expect(@redises.xlen(@key)).to eq 4
end
end