Skip to content

ERR wrong number of arguments for 'hset' command #658

Closed

Description

@Adre

Describe the bug
Calling ab_test(:homepage_seo, { "missing"=>1 }) in a Rails controller results in the following error:

   Redis::CommandError:
       ERR wrong number of arguments for 'hset' command
     # /usr/local/bundle/gems/redis-4.2.0/lib/redis/client.rb:127:in `call'
     # /usr/local/bundle/gems/redis-4.2.0/lib/redis.rb:2117:in `block in hset'
     # /usr/local/bundle/gems/redis-4.2.0/lib/redis.rb:56:in `block in synchronize'
     # /usr/local/bundle/gems/redis-4.2.0/lib/redis.rb:56:in `synchronize'
     # /usr/local/bundle/gems/redis-4.2.0/lib/redis.rb:2116:in `hset'
     # /usr/local/bundle/gems/split-4.0.0.pre/lib/split/experiment.rb:90:in `save'
     # /usr/local/bundle/gems/split-4.0.0.pre/lib/split/helper.rb:13:in `ab_test'
     # ./app/controllers/concerns/seo_meta_tags_concern.rb:36:in `set_home_page_meta_tags'
     # ./app/controllers/pages_controller.rb:16:in `home'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/abstract_controller/base.rb:194:in `process_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal/rendering.rb:30:in `process_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/abstract_controller/callbacks.rb:42:in `block in process_action'
     # /usr/local/bundle/gems/activesupport-5.2.4.6/lib/active_support/callbacks.rb:132:in `run_callbacks'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/abstract_controller/callbacks.rb:41:in `process_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal/rescue.rb:22:in `process_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
     # /usr/local/bundle/gems/activesupport-5.2.4.6/lib/active_support/notifications.rb:168:in `block in instrument'
     # /usr/local/bundle/gems/activesupport-5.2.4.6/lib/active_support/notifications/instrumenter.rb:23:in `instrument'
     # /usr/local/bundle/gems/activesupport-5.2.4.6/lib/active_support/notifications.rb:168:in `instrument'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal/instrumentation.rb:32:in `process_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
     # /usr/local/bundle/gems/activerecord-5.2.4.6/lib/active_record/railties/controller_runtime.rb:24:in `process_action'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/abstract_controller/base.rb:134:in `process'
     # /usr/local/bundle/gems/actionview-5.2.4.6/lib/action_view/rendering.rb:32:in `process'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal.rb:191:in `dispatch'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_controller/metal.rb:252:in `dispatch'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/routing/route_set.rb:34:in `serve'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/journey/router.rb:52:in `block in serve'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/journey/router.rb:35:in `each'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/journey/router.rb:35:in `serve'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/routing/route_set.rb:840:in `call'
     # /usr/local/bundle/gems/serviceworker-rails-0.6.0/lib/serviceworker/middleware.rb:35:in `call'
     # /usr/local/bundle/gems/rack-attack-5.4.2/lib/rack/attack.rb:182:in `call'
     # /usr/local/bundle/gems/coverband-5.1.0/lib/coverband/integrations/background_middleware.rb:10:in `call'
     # /usr/local/bundle/gems/rack-attack-5.4.2/lib/rack/attack.rb:182:in `call'
     # /usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:36:in `block in call'
     # /usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `catch'
     # /usr/local/bundle/gems/warden-1.2.9/lib/warden/manager.rb:34:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/tempfile_reaper.rb:15:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/etag.rb:27:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/deflater.rb:44:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/conditional_get.rb:27:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/head.rb:12:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/http/content_security_policy.rb:18:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:266:in `context'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/session/abstract/id.rb:260:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/cookies.rb:670:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
     # /usr/local/bundle/gems/activesupport-5.2.4.6/lib/active_support/callbacks.rb:98:in `run_callbacks'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/callbacks.rb:26:in `call'
     # /usr/local/bundle/gems/appsignal-3.0.4/lib/appsignal/rack/rails_instrumentation.rb:19:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
     # /usr/local/bundle/gems/lograge-0.11.2/lib/lograge/rails_ext/rack/logger.rb:15:in `call_app'
     # /usr/local/bundle/gems/railties-5.2.4.6/lib/rails/rack/logger.rb:28:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
     # /usr/local/bundle/gems/request_store-1.5.0/lib/request_store/middleware.rb:19:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/request_id.rb:27:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/method_override.rb:24:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/runtime.rb:22:in `call'
     # /usr/local/bundle/gems/rack-rewrite-1.5.1/lib/rack/rewrite.rb:24:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/executor.rb:14:in `call'
     # /usr/local/bundle/gems/actionpack-5.2.4.6/lib/action_dispatch/middleware/static.rb:127:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/sendfile.rb:110:in `call'
     # /usr/local/bundle/gems/railties-5.2.4.6/lib/rails/engine.rb:524:in `call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/urlmap.rb:74:in `block in call'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/urlmap.rb:58:in `each'
     # /usr/local/bundle/gems/rack-2.2.3/lib/rack/urlmap.rb:58:in `call'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/mock_session.rb:29:in `request'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/test.rb:266:in `process_request'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/test.rb:129:in `custom_request'
     # /usr/local/bundle/gems/rack-test-1.1.0/lib/rack/test.rb:58:in `get'
     # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/rack_test/browser.rb:72:in `process'
     # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/rack_test/browser.rb:47:in `process_and_follow_redirects'
     # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/rack_test/browser.rb:24:in `visit'
     # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/rack_test/driver.rb:46:in `visit'
     # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/session.rb:278:in `visit'
     # /usr/local/bundle/gems/capybara-3.35.3/lib/capybara/dsl.rb:58:in `block (2 levels) in <module:DSL>'
     # ./spec/features/home_page_spec.rb:3:in `block (2 levels) in <top (required)>'
     # /usr/local/bundle/gems/webmock-3.13.0/lib/webmock/rspec.rb:37:in `block (2 levels) in <top (required)>'

To Reproduce
using the following combination of gems:

Rails v 5.2.4.6
Split v 4.0.0.pre
Redis v 4.2.5 (also tested 4.2.0)

  1. run a rails console
  2. Split::Helper.ab_test(:new_user_free_points, '100', '200', '300')
  3. See error

Expected behavior
No argument error is expected.

Additional context
The issue was introduced to our codebase when updating from split 3.4.1 to the 4.0.0.pre release to resolve the following deprecation error:

Redis#exists(key) will return an Integer in redis-rb 4.3. exists? returns a boolean, you should use it instead. To opt-in to the new behavior now you can set Redis.exists_returns_integer = true. To disable this message and keep the current (boolean) behaviour of 'exists' you can set Redis.exists_returns_integer = false, but this option will be removed in 5.0. (/usr/local/bundle/gems/split-3.4.1/lib/split/experiment.rb:104:in `new_record?')

We were already using redis 4.2.5 before updating split.

I haven't tested this theory, but the issue may have been introduced in commit 930873f which talks about changing multiple hset calls into a single hmset, but the new code still uses hset. Hope that helps.

Let me know if you need anything else or there's anything I can do to help.

Activity

  1. andrehjr commented on May 19, 2021

    @andrehjr
    Member

    Hi @Adre 🙌 Thanks for bringing this out.

    Which redis version are you currently using? HMSET was deprecated on redis 4.0, and HSET will work with multiple arguments.

    But as we're still supporting Redis < 4.0 I guess that should change to hmset. I can fix that and release a new version later today.

  2. Adre commented on May 19, 2021

    @Adre
    Author

    Hi @andrehjr - no problem!

    We're using redis 4.2.5, which worked fine with split 3.4.1, but presents the issue after updating to split 4.0.0.pre

    Don't forget, split 4.0.0.pre already requires redis >= 4.2 so I'm unable to test this against older versions of redis 😬

  3. andrehjr commented on May 19, 2021

    @andrehjr
    Member

    Hi @Adre! Sorry for the confusion.

    I meant the redis server version, not the gem. For example If you run Redis.new.info["redis_version"].

    https://redis.io/commands/hset accepts multiple args after 4.0 :)

    The fix should be easy enough. Do you want to submit a PR for it? Should be basically change hset -> hmset at that point.

  4. Adre commented on May 20, 2021

    @Adre
    Author

    Oh, I see! 😆

    You're absolutely right, turns out we're using Redis 3.2 in development, although we're actually using 5.0 in production. Looks like we need to update our development environment in this case to get parity, which should solve my particular problem.

    I'm happy to put in a PR as you suggested if you're committed to supporting Redis <4.0, but as far as I can tell from the Redis release cycle page these versions are no longer maintained/supported?

  5. andrehjr commented on May 20, 2021

    @andrehjr
    Member

    Awesome! I've already pushed #659 to keep compatibility. Just in case someone is still using Redis < 4.

    But in the future, we may drop that support if it turns out to be difficult to maintain. 🙌

  6. Adre commented on May 20, 2021

    @Adre
    Author

    Thanks for the help @andrehjr - loving your work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions