Comments (2)
I started a fork to work on this last night and realized the extent of this issue is pretty deep. There were a lot of changes in the upgrade to version 5 that will have a lot of impact on this gem. That I think ultimately needs to be a larger conversation than just fixing this bug.
One of the biggest questions would be does this gem want to maintain backwards compatibility with version 4 or not.
Some others would include, is fixing this bug alone enough or would all of the methods effected need to be handled before the changes will be committed?
In the meantime, may I offer the following as a workaround for those that are using >= version 5:
class MockRedis
module SetMethods
def sadd(key, members)
# members_class = members.class
members = Array(members).map(&:to_s)
assert_has_args(members, 'sadd')
with_set_at(key) do |s|
size_before = s.size
if members.size > 1
members.reverse_each { |m| s << m }
s.size - size_before
else
added = !!s.add?(members.first)
# if members_class == Array
s.size - size_before
# else
# added
# end
end
end
end
def srem(key, members)
with_set_at(key) do |s|
if members.is_a?(Array)
orig_size = s.size
members = members.map(&:to_s)
s.delete_if { |m| members.include?(m) }
orig_size - s.size
else
# !!s.delete?(members.to_s)
s.delete?(members.to_s) ? 1 : 0
end
end
end
end
end
Comments about the above suggestion
If the specs are updated to expect the new output. This passes the bulk of the tests in the gem, all failures for the srem
and sadd
specs are from breaking changes in version 5. All but one of the failures coming from it_should_behave_like 'a set-only command'
:
let(:redis_gem_v5?) { Redis::VERSION.to_i == 5 }
let(:positive_response) { redis_gem_v5? ? 1 : true }
let(:negative_response) { redis_gem_v5? ? 0 : false }
it 'returns positive response if member is in the set' do
expect(@redises.srem(@key, 'bert')).to eq(positive_response)
end
it 'returns negative response if member is not in the set' do
expect(@redises.srem(@key, 'cookiemonster')).to eq(negative_response)
end
from mock_redis.
Thanks for the research and providing a workaround!
I'm supportive of dropping support for older Redis gem versions as part of fixing in the project itself. At some point the ecosystem needs to move forward.
from mock_redis.
Related Issues (20)
- Ruby 3.0 support HOT 1
- Support for M1
- Not mention XADD was supported for this gem, right? HOT 2
- Add :get keyword to #set method. HOT 1
- Moneta 1.5 support HOT 1
- Unknown keywords: :path, ... after updating to redis-rb 4.7.0
- Release new version HOT 2
- Use MockRedis with Redis::Connection.drivers HOT 3
- deprecation warning
- Incompatible with the new 'redis-client' gem HOT 8
- ArgumentError after update ruby from 3.1.2 to 3.2.0 HOT 4
- Add #sadd? to match redis-rb v4.8.0 HOT 1
- Add additional arg to lpop to allow popping multiple records
- TypeError when using `eval()` HOT 1
- Add support for zadd ch, gt, lt options
- Unable to execute `#call` with redis command in `pipelined` HOT 1
- Add :exat and :pxat keywords to #set method HOT 1
- Add support for `EXPIRE` command options HOT 1
- ArgumentError: wrong number of arguments (given 3, expected 2) When used in conjunction with redis-store HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mock_redis.