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

Unable to execute #call with redis command in pipelined #278

Closed
viralpraxis opened this issue Oct 3, 2023 · 1 comment · Fixed by #283
Closed

Unable to execute #call with redis command in pipelined #278

viralpraxis opened this issue Oct 3, 2023 · 1 comment · Fixed by #283
Labels
contributions-welcome Contributions from anyone are welcome enhancement

Comments

@viralpraxis
Copy link
Contributor

viralpraxis commented Oct 3, 2023

Gem version: 0.37.0

Hi! I'm not sure if it was already mentioned in earlier issues. I observe that performing call inside pipeline raises an exception:

redis_client = MockRedis.new

results = redis_client.pipelined do |pipeline|
  pipeline.call(["expire", "foobar", 42])
end

results[0]
# => #<NoMethodError: undefined method `call' for #<MockRedis::Database:0x000055cbbadfa328>

Ordinary operations do work as expected:

redis_client.call(["set", "foobar", 42])
# => "OK"
redis_client.call(["expire", "foobar", 42])
# => true

And original redis-client (4.5.1) works as expected too:

redis_client.pipelined do |pipeline|
  pipeline.call(["set", "foobar", "val"])
  pipeline.call(["expire", "foobar", 1337])
  pipeline.call(["ttl", "foobar"])
end 

=begin
[
    [0] "OK",
    [1] 1,
    [2] 1337
]
=end

Could you please clarify it it's an unimplemented feature or a bug?

@sds
Copy link
Owner

sds commented Oct 25, 2023

Likely was never supported. Happy to merge a PR adding support!

@sds sds added the contributions-welcome Contributions from anyone are welcome label Oct 25, 2023
@sds sds closed this as completed in #283 Oct 29, 2023
sds pushed a commit that referenced this issue Oct 29, 2023
Resolves #278

Seems like everything is working; however, I'm not sure if moving
`#call` from `MockRedis` to `MockRedis::Database` has some side-effects
-- is there a reason `call` was separated from other commands?

I also changed `send` to `public_send` in `call` implementation (seems
to be OK, I'm not sure if there are any edge cases when calling private
is a usecase).

Also, I think we should allow mix-cased variants of Redis methods
(`RedisMock.new.call(["GET", 123])` does not work right now, but redis
commands are case insensitive).

Usage example:

```ruby
redis = MockRedis.new

redis.pipelined do |pipeline|
  pipeline.call(["get", "foo"])
  pipeline.call(["get", "bar"])
end
```

Co-authored-by: ya2k <yk@wfolio.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributions-welcome Contributions from anyone are welcome enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants