Closed gsecillano closed 11 years ago
All values in Memcached itself are strings (byte arrays, technically).
How does increment work in this case?
This doesn't seem to have feature parity with memcache-client.
Increment works because the server itself serializes and deserializes the value to an ASCII string.
Feature parity with memcache-client isn't really the goal; what problem did you encounter?
On Wednesday, May 1, 2013, gsecillano wrote:
This doesn't seem to have feature parity with memcache-client.
On 2013-05-01, at 4:40 PM, Evan Weaver <notifications@github.com<javascript:_e({}, 'cvml', 'notifications@github.com');>> wrote:
All values in Memcached itself are strings (byte arrays, technically).
— Reply to this email directly or view it on GitHub.
— Reply to this email directly or view it on GitHubhttps://github.com/evan/memcached/issues/119#issuecomment-17315735 .
2 issues: -Cannot store true as raw (Cannot convert true into String) -My server does not increment, saying the value stored is non-numeric.
I will post the specs later.
Again, true is a rich type and must be serialized to a string. If you use raw=false to marshal the object it will work.
Did you initialize the key to "0" (a string with the single character 0) before trying to increment it?
IRB:
1.8.7 :002 > require 'memcached/rails'
=> true
1.8.7 :003 > c = Memcached::Rails.new
=> #<Memcached::Rails:0x7f4867ac8878 @notstored=#
=> 0
$ memcached -vv
30: Client using the ascii protocol
<30 get foo
>30 END
<30 set foo 0 604800 4
>30 STORED
<30 incr foo 1
>30 CLIENT_ERROR cannot increment or decrement non-numeric value
<30 connection closed.
<30 new auto-negotiating client connection
30: Client using the ascii protocol
<30 set foo 0 604800 5
>30 STORED
<30 incr foo 1
>30 CLIENT_ERROR cannot increment or decrement non-numeric value
<30 connection closed.
Gem's tests all pass.
ruby 1.8.7 (2012-02-08 MBARI 8/0x6770 on patchlevel 358) [x86_64-linux], MBARI 0x6770, Ruby Enterprise Edition 2012.02
memcached 1.4.14-0ubuntu1 amd64
By default it sets the Marshaled string which is not ASCII. Initialize your key with:
c.set 'foo', '0', true
Yes, I was about to respond saying that I did exactly that. Now increment works. Thanks!
Great, ok. It is a known bug that the error isn't reported properly: #110
On Thu, May 2, 2013 at 11:59 AM, gsecillano notifications@github.comwrote:
Yes, I was about to respond saying that I did exactly that. Now increment works. Thanks!
— Reply to this email directly or view it on GitHubhttps://github.com/evan/memcached/issues/119#issuecomment-17357518 .
1.8.7 :001 > require 'memcached/rails', @default_ttl=604800, @string_return_types=nil, @not_found=#, @logger=nil, struct=#Rlibmemcached::MemcachedSt:0x7f202eceb5a8, @options={:timeout=>0.25, :prefix_delimiter=>"", :sort_hosts=>false, :verify_key=>true, :tcp_nodelay=>false, :retry_timeout=>30, :noreply=>false, :default_ttl=>04800, :use_udp=>false, :cache_lookups=>true, :rcv_timeout=>0.25, :default_weight=>8, :binary_protocol=>false, :hash_with_prefix_key=>true, :server_failure_limit=>2, :no_block=>false, :distribution=>:consistent_keama, :experimental_features=>false, :ketama_weighted=>true, :prefix_key=>"", :poll_timeout=>0.25, :auto_eject_hosts=>true, :exception_retry_limit=>5, :hash=>:fnv1_32, :support_cas=>false, :show_backtraces=>false, buffer_requests=>false, :connect_timeout=>4, :credentials=>nil, :exceptions_to_retry=>[Memcached::ServerIsMarkedDead, Memcached::ATimeoutOccurred, Memcached::ConnectionBindFailure, Memcached::ConnectionFailure, Mecached::ConnectionSocketCreateFailure, Memcached::Failure, Memcached::MemoryAllocationFailure, Memcached::ReadFailure, Memcached::ServerEnd, Memcached::ServerError, Memcached::SystemError, Memcached::UnknownReadFalure, Memcached::WriteFailure, Memcached::SomeErrorsWereReported]}>
1.8.7 :003 > c.write 'a', 1, :raw => true
=> true 1.8.7 :002 > c = Memcached::Rails.new
=> #<Memcached::Rails:0x7f202ecebad0 @not_stored=#
TypeError: can't convert Fixnum into String from /home/george/.bundles/cubetree/ruby/1.8/gems/memcached-1.5.0/lib/memcached/memcached.rb:306:in
memcached_set' from /home/george/.bundles/cubetree/ruby/1.8/gems/memcached-1.5.0/lib/memcached/memcached.rb:306:in
set' from /home/george/.bundles/cubetree/ruby/1.8/gems/memcached-1.5.0/lib/memcached/rails.rb:88:inset' from /home/george/.bundles/cubetree/ruby/1.8/gems/memcached-1.5.0/lib/memcached/rails.rb:100:in
write' from (irb):3 1.8.7 :004 >