sorentwo / readthis

:newspaper: Pooled active support compliant caching with redis
MIT License
506 stars 40 forks source link

Incompatible character encodings: UTF-8 and ASCII-8BIT #52

Closed deniskorobicyn closed 7 years ago

deniskorobicyn commented 7 years ago

Hello! There is a problem when I try to save some russian symbols by russian key.

Here is an example to reproduce it:

it 'stores russian symbols by russian key' do
  cache.write('вгдмн', 'вгдмн')

  expect(cache.read('вгдмн')).to eq('вгдмн')
end

Stacktrace:

 1) Readthis::Cache#write stores russian symbols by russian key
     Failure/Error: store.set(namespaced, dumped)

     Encoding::CompatibilityError:
       incompatible character encodings: UTF-8 and ASCII-8BIT
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/connection/command_helper.rb:28:in `join'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/connection/command_helper.rb:28:in `build_command'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/connection/ruby.rb:374:in `write'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:271:in `block in write'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:250:in `io'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:269:in `write'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:228:in `block (3 levels) in process'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:222:in `each'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:222:in `block (2 levels) in process'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:367:in `ensure_connected'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:221:in `block in process'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:306:in `logging'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:220:in `process'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis/client.rb:120:in `call'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis.rb:754:in `block in set'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis.rb:58:in `block in synchronize'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis.rb:58:in `synchronize'
     # /bundle/2.3/gems/redis-3.3.2/lib/redis.rb:750:in `set'
     # ./lib/readthis/cache.rb:398:in `write_entity'
     # ./lib/readthis/cache.rb:106:in `block in write'
     # /bundle/2.3/gems/connection_pool-2.2.1/lib/connection_pool.rb:64:in `block (2 levels) in with'
     # /bundle/2.3/gems/connection_pool-2.2.1/lib/connection_pool.rb:63:in `handle_interrupt'
     # /bundle/2.3/gems/connection_pool-2.2.1/lib/connection_pool.rb:63:in `block in with'
     # /bundle/2.3/gems/connection_pool-2.2.1/lib/connection_pool.rb:60:in `handle_interrupt'
     # /bundle/2.3/gems/connection_pool-2.2.1/lib/connection_pool.rb:60:in `with'
     # ./lib/readthis/cache.rb:427:in `block in invoke'
     # ./lib/readthis/cache.rb:421:in `instrument'
     # ./lib/readthis/cache.rb:426:in `invoke'
     # ./lib/readthis/cache.rb:105:in `write'
     # ./spec/readthis/cache_spec.rb:38:in `block (3 levels) in <top (required)>'

My setup:

Also on redis-store they had same problem and fixed it with commit https://github.com/shingara/redis-store/commit/113d6e6a9f259d9095c103e0dcf3982e986ce8f7. Connected issue on redis-rb - https://github.com/redis/redis-rb/issues/128.

Would it be a good solution here? If not, what do you recommend to avoid this?

sorentwo commented 7 years ago

Thanks for reporting this. It has been fixed and I've released v2.0.2 with just this change.

deniskorobicyn commented 7 years ago

Yay! Thanks! :+1: