redis / hiredis-rb

Ruby wrapper for hiredis
BSD 3-Clause "New" or "Revised" License
320 stars 90 forks source link

Errno::EINVAL: Invalid argument when using hiredis #55

Open danarnold opened 5 years ago

danarnold commented 5 years ago

When I connect to a server with authentication, I get the following error:

Errno::EINVAL: Invalid argument
from /home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/connection/hiredis.rb:19:in `connect'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/connection/hiredis.rb:19:in `connect'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:342:in `establish_connection'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:104:in `block in connect'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:299:in `with_reconnect'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:103:in `connect'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:372:in `ensure_connected'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:224:in `block in process'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:312:in `logging'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:223:in `process'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/client.rb:123:in `call'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis.rb:561:in `block in keys'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis.rb:50:in `block in synchronize'
/home/dan/.rvm/rubies/ruby-2.5.3/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis.rb:50:in `synchronize'
/home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis.rb:560:in `keys'
(pry):7:in `__pry__'

Steps to reproduce:

$ pry
[1] pry(main)> require 'redis'
=> true
[2] pry(main)> require 'hiredis'
=> true
[3] pry(main)> conn = Redis.new(url: 'redis://:REDACTED@redacted.ec2.cloud.redislabs.com:16900')
=> #<Redis client v4.1.0 for redis://redacted.ec2.cloud.redislabs.com:16900/0>
[4] pry(main)> conn.get 'queues'
=> nil
[5] pry(main)> conn2 = Redis.new(url: 'redis://:REDACTED
@redacted.ec2.cloud.redislabs.com:16900', driver: :hiredis)
=> #<Redis client v4.1.0 for redis://redacted.ec2.cloud.redislabs.com:16900/0>
[7] pry(main)> conn2.keys '*'
Errno::EINVAL: Invalid argument
from /home/dan/.rvm/gems/ruby-2.5.3@gemset/gems/redis-4.1.0/lib/redis/connection/hiredis.rb:19:in `connect'

Note that although I've redacted our server URL and credentials for obvious reasons, the arguments are the same. Only the driver is different.

My environment:

$ uname -a
Linux arcturus 4.4.0-17763-Microsoft #253-Microsoft Mon Dec 31 17:49:00 PST 2018 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.1 LTS
Release:        18.04
Codename:       bionic

I suspect it might be related to my environment, since I have not experienced this error on macOS. However, I have not had issues with any of the other development tools I've used, including many with native extensions as hiredis has.

N0xFF commented 5 years ago

Try this:

require "hiredis/ruby/connection"
Hiredis::Connection = Hiredis::Ruby::Connection
danarnold commented 5 years ago

That does prevent the error and allow a successful connection.