Skip to content

Commit

Permalink
Update redis-rb dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Nov 19, 2019
1 parent 13b0ecd commit 871723b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 46 deletions.
1 change: 0 additions & 1 deletion .gitignore
@@ -1,7 +1,6 @@
*.gem
.bundle
Gemfile.lock
gemfiles/*.gemfile.lock
pkg/*
.rvmrc
*.rbc
Expand Down
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -12,10 +12,6 @@ rvm:
- jruby
- rbx-2

gemfile:
- Gemfile
- gemfiles/redisrb-master.gemfile

matrix:
allow_failures:
- rvm: rbx-2
2 changes: 1 addition & 1 deletion fakeredis.gemspec
Expand Up @@ -18,6 +18,6 @@ Gem::Specification.new do |s|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.add_runtime_dependency(%q<redis>, ["~> 3"])
s.add_runtime_dependency(%q<redis>, ["~> 4.1"])
s.add_development_dependency(%q<rspec>, ["~> 3.0"])
end
14 changes: 0 additions & 14 deletions gemfiles/redisrb-master.gemfile

This file was deleted.

8 changes: 0 additions & 8 deletions lib/fakeredis/command_executor.rb
Expand Up @@ -15,14 +15,6 @@ def write(command)
raise Redis::CommandError, "ERR unknown command '#{meffod}'"
end

if reply == true
reply = 1
elsif reply == false
reply = 0
elsif reply.is_a?(Array)
reply = reply.map { |r| r == true ? 1 : r == false ? 0 : r }
end

replies << reply
nil
end
Expand Down
30 changes: 21 additions & 9 deletions lib/redis/connection/memory.rb
Expand Up @@ -95,9 +95,8 @@ def disconnect

def client(command, _options = {})
case command
when :setname then true
when :setname then "OK"
when :getname then nil
when :client then true
else
raise Redis::CommandError, "ERR unknown command '#{command}'"
end
Expand Down Expand Up @@ -867,10 +866,10 @@ def set(key, value, *array_options)
option_nx = array_options.delete("NX")
option_xx = array_options.delete("XX")

return false if option_nx && option_xx
return nil if option_nx && option_xx

return false if option_nx && exists(key)
return false if option_xx && !exists(key)
return nil if option_nx && exists(key)
return nil if option_xx && !exists(key)

data[key] = value.to_s

Expand Down Expand Up @@ -1095,7 +1094,7 @@ def zpopmax(key, count = nil)
results.each do |member|
zrem(key, member.first)
end
count.nil? ? results.first : results
count.nil? ? results.first : results.flatten
end

def zpopmin(key, count = nil)
Expand All @@ -1106,7 +1105,7 @@ def zpopmin(key, count = nil)
results.each do |member|
zrem(key, member.first)
end
count.nil? ? results.first : results
count.nil? ? results.first : results.flatten
end

def bzpopmax(*args)
Expand All @@ -1125,7 +1124,13 @@ def zcard(key)
def zscore(key, value)
data_type_check(key, ZSet)
value = data[key] && data[key][value.to_s]
value && value.to_s
if value == Float::INFINITY
"inf"
elsif value == -Float::INFINITY
"-inf"
elsif value
value.to_s
end
end

def zcount(key, min, max)
Expand All @@ -1139,7 +1144,14 @@ def zincrby(key, num, value)
data[key] ||= ZSet.new
data[key][value.to_s] ||= 0
data[key].increment(value.to_s, num)
data[key][value.to_s].to_s

if num =~ /^\+?inf/
"inf"
elsif num == "-inf"
"-inf"
else
data[key][value.to_s].to_s
end
end

def zrank(key, value)
Expand Down
10 changes: 3 additions & 7 deletions spec/memory_spec.rb
Expand Up @@ -86,16 +86,12 @@ def result
end

describe '#client' do
it 'returns 1 when command is :setname' do
expect(redis.write([:client, :setname])).to eq 1
it 'returns OK when command is :setname' do
expect(redis.client(:setname, 'my-client-01')).to eq 'OK'
end

it 'returns nil when command is :getname' do
expect(redis.write([:client, :getname])).to eq nil
end

it 'returns true when the comment is :client with an argument' do
expect(redis.write([:client, :client, :list])).to eq 1
expect(redis.client(:getname)).to eq nil
end

it 'raises error for other commands' do
Expand Down
4 changes: 2 additions & 2 deletions spec/sorted_sets_spec.rb
Expand Up @@ -107,14 +107,14 @@ module FakeRedis
@client.zadd("key", [1, "val1", 2, "val2", 3, "val3"])
expect(@client.zpopmax("key")).to eq(["val3", 3.0])
expect(@client.zpopmax("key", 3)).to eq([["val2", 2.0], ["val1", 1.0]])
expect(@client.zpopmax("nonexistent")).to eq([])
expect(@client.zpopmax("nonexistent")).to eq(nil)
end

it "should pop members with the lowest scores from sorted set" do
@client.zadd("key", [1, "val1", 2, "val2", 3, "val3"])
expect(@client.zpopmin("key")).to eq(["val1", 1.0])
expect(@client.zpopmin("key", 3)).to eq([["val2", 2.0], ["val3", 3.0]])
expect(@client.zpopmin("nonexistent")).to eq([])
expect(@client.zpopmin("nonexistent")).to eq(nil)
end

it "should pop members with the highest score from first sorted set that is non-empty" do
Expand Down

0 comments on commit 871723b

Please sign in to comment.