redis-namespace
redis-namespace copied to clipboard
force key encoding to binary to avoid UTF-8 issues
Somehow I ended up with keys in redis that contained invalid UTF-8 characters, which is now causing problems trying to retrieve them.
My code is currently failing with this stacktrace:
ArgumentError: invalid byte sequence in UTF-8
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:380:in `gsub'
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:380:in `rem_namespace'
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:376:in `block in rem_namespace'
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:376:in `map'
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:376:in `rem_namespace'
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:338:in `method_missing'
from /var/ruby/vendor/bundle/ruby/2.0.0/gems/redis-namespace-1.3.2/lib/redis/namespace.rb:227:in `keys'
pointing to the source of the problem being the .sub method of the key name.
I was able to get around this issue by forcing the string encoding to binary, which still successfully removes the namespace prefix from the keys.
Okay well it looks like my fix fails in ruby 1.9.3 and below for various reasons. Any better suggestions?
Okay I fixed this for all versions except 1.8.7 which doesn't have the concept of string encodings, so doesn't need fixing. I added a test case demonstrating how it failed in the first place.
@aaronpk I know this is an old once, but could you rebase on master so the latest tests run?