-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for
memory usage ...
command
- Loading branch information
1 parent
bc05694
commit 312f239
Showing
3 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class MockRedis | ||
module MemoryMethod | ||
def memory(usage, key = nil, *_options) | ||
raise ArgumentError, "unhandled command `memory #{usage}`" if usage != 'usage' | ||
|
||
return nil unless @data.key?(key) | ||
|
||
160 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe '#memory usage [mock only]' do | ||
it 'only handles the usage subcommand' do | ||
expect { @redises.mock.call(%w[memory stats]) }.to raise_error(ArgumentError) | ||
end | ||
|
||
context 'when the key does not exist' do | ||
before { @redises.real.del('foo') } | ||
|
||
it 'returns nil' do | ||
expect(@redises.call(%w[memory usage foo])).to be_nil | ||
end | ||
end | ||
|
||
context 'when the key does exist' do | ||
before { @redises.set('foo', 'a' * 100) } | ||
|
||
it 'returns the memory usage' do | ||
expect(@redises.call(%w[memory usage foo])).to be_a(Integer) | ||
end | ||
end | ||
end |