Skip to content

Instantly share code, notes, and snippets.

@joshuaclayton
Created October 31, 2009 14:24
Show Gist options
  • Select an option

  • Save joshuaclayton/223093 to your computer and use it in GitHub Desktop.

Select an option

Save joshuaclayton/223093 to your computer and use it in GitHub Desktop.
# new IRB session, memcached 1.4.1 - looks like it marshalled the data incorrectly?
>> gem "memcache-client", "1.7.4"
=> true
>> require 'memcache'
=> true
>> mc = MemCache.new("localhost:11211")
=> <MemCache: 1 servers, ns: nil, ro: false>
>>
?> text = %(
get: ["Throttle:exp:"]
set: ["Throttle:exp:", 1256996309, 1256996369]
get: ["Throttle:bkt::0"]
set: ["Throttle:exp:", 1256996309, 1256996369]
add: ["Throttle:sum::0", 0, 60]
add: ["Throttle:bkt::0", 0, 60]
get: ["Throttle:sum::0"]
incr: ["Throttle:bkt::0", 1]
get: ["Throttle:bkt::0"])
=> "\nget: [\"Throttle:exp:\"]\nset: [\"Throttle:exp:\", 1256996309, 1256996369]\nget: [\"Throttle:bkt::0\"]\nset: [\"Throttle:exp:\", 1256996309, 1256996369]\nadd: [\"Throttle:sum::0\", 0, 60]\nadd: [\"Throttle:bkt::0\", 0, 60]\nget: [\"Throttle:sum::0\"]\nincr: [\"Throttle:bkt::0\", 1]\nget: [\"Throttle:bkt::0\"]"
>>
?> mc.flush_all
=> [<MemCache::Server: localhost:11211 [1] (CONNECTED)>]
>> puts "parsing commands"
parsing commands
=> nil
>> text.split("\n").each do |line|
?> next if line.strip == ""
>> cmd, args = line.split(": ")
>> args = eval(args)
>> puts "Command: #{cmd}\nArgs: #{args.join(",")}"
>> result = mc.send(cmd, *args)
>> puts "Result: #{result} (#{mc.get(args.first).class})"
>> puts "\n"
>> end
Command: get
Args: Throttle:exp:
Result: (NilClass)
Command: set
Args: Throttle:exp:,1256996309,1256996369
Result: STORED
(NilClass)
Command: get
Args: Throttle:bkt::0
Result: (NilClass)
Command: set
Args: Throttle:exp:,1256996309,1256996369
Result: STORED
(NilClass)
Command: add
Args: Throttle:sum::0,0,60
Result: STORED
(Fixnum)
Command: add
Args: Throttle:bkt::0,0,60
Result: STORED
(Fixnum)
Command: get
Args: Throttle:sum::0
Result: 0 (Fixnum)
Command: incr
Args: Throttle:bkt::0,1
MemCache::MemCacheError: cannot increment or decrement non-numeric value
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:868:in `raise_on_error_response!'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:773:in `cache_incr'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:807:in `call'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:807:in `with_socket_management'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:769:in `cache_incr'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:298:in `incr'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:828:in `with_server'
from /Users/joshuaclayton/.rvm/gems/ruby-enterprise/1.8.7/gems/memcache-client-1.7.4/lib/memcache.rb:297:in `incr'
from (irb):23:in `send'
from (irb):23
from (irb):18:in `each'
from (irb):18
>> puts "finished parsing commands"
finished parsing commands
=> nil
# new IRB session, memcached 1.4.1 - increment doesn't work
>> gem "memcache-client", "1.5.0"
=> true
>> require 'memcache'
=> true
>> mc = MemCache.new("localhost:11211")
=> <MemCache: 1 servers, 1 buckets, ns: nil, ro: false>
>>
?> text = %(
get: ["Throttle:exp:"]
set: ["Throttle:exp:", 1256996309, 1256996369]
get: ["Throttle:bkt::0"]
set: ["Throttle:exp:", 1256996309, 1256996369]
add: ["Throttle:sum::0", 0, 60]
add: ["Throttle:bkt::0", 0, 60]
get: ["Throttle:sum::0"]
incr: ["Throttle:bkt::0", 1]
get: ["Throttle:bkt::0"])
=> "\nget: [\"Throttle:exp:\"]\nset: [\"Throttle:exp:\", 1256996309, 1256996369]\nget: [\"Throttle:bkt::0\"]\nset: [\"Throttle:exp:\", 1256996309, 1256996369]\nadd: [\"Throttle:sum::0\", 0, 60]\nadd: [\"Throttle:bkt::0\", 0, 60]\nget: [\"Throttle:sum::0\"]\nincr: [\"Throttle:bkt::0\", 1]\nget: [\"Throttle:bkt::0\"]"
>>
?> mc.flush_all
=> [<MemCache::Server: localhost:11211 [1] (CONNECTED)>]
>> puts "parsing commands"
parsing commands
=> nil
>> text.split("\n").each do |line|
?> next if line.strip == ""
>> cmd, args = line.split(": ")
>> args = eval(args)
>> puts "Command: #{cmd}\nArgs: #{args.join(",")}"
>> result = mc.send(cmd, *args)
>> puts "Result: #{result} (#{mc.get(args.first).class})"
>> puts "\n"
>> end
Command: get
Args: Throttle:exp:
Result: (NilClass)
Command: set
Args: Throttle:exp:,1256996309,1256996369
Result: (NilClass)
Command: get
Args: Throttle:bkt::0
Result: (NilClass)
Command: set
Args: Throttle:exp:,1256996309,1256996369
Result: (NilClass)
Command: add
Args: Throttle:sum::0,0,60
Result: STORED
(Fixnum)
Command: add
Args: Throttle:bkt::0,0,60
Result: STORED
(Fixnum)
Command: get
Args: Throttle:sum::0
Result: 0 (Fixnum)
Command: incr
Args: Throttle:bkt::0,1
Result: 0 (Fixnum)
Command: get
Args: Throttle:bkt::0
Result: 0 (Fixnum)
=> ["", "get: [\"Throttle:exp:\"]", "set: [\"Throttle:exp:\", 1256996309, 1256996369]", "get: [\"Throttle:bkt::0\"]", "set: [\"Throttle:exp:\", 1256996309, 1256996369]", "add: [\"Throttle:sum::0\", 0, 60]", "add: [\"Throttle:bkt::0\", 0, 60]", "get: [\"Throttle:sum::0\"]", "incr: [\"Throttle:bkt::0\", 1]", "get: [\"Throttle:bkt::0\"]"]
>> puts "finished parsing commands"
finished parsing commands
=> nil
So, long story short, I've tried both memcached 1.2.8, 1.4.1, and 1.4.2 and memcache-client versions 1.5.0, 1.7.4, and 1.7.5.
None work on Snow Leopard (I'd never played with memcache/memcache-client on Leopard) properly, as far as I can tell.
# copy/paste this into IRB if you want - make sure you're running memcached on port 11211 locally first.
gem "memcache-client", "1.7.5" # or "1.5.0"
require 'memcache'
mc = MemCache.new("localhost:11211")
text = %(
get: ["Throttle:exp:"]
set: ["Throttle:exp:", 1256996309, 1256996369]
get: ["Throttle:bkt::0"]
set: ["Throttle:exp:", 1256996309, 1256996369]
add: ["Throttle:sum::0", 0, 60]
add: ["Throttle:bkt::0", 0, 60]
get: ["Throttle:sum::0"]
incr: ["Throttle:bkt::0", 1]
get: ["Throttle:bkt::0"])
mc.flush_all
puts "parsing commands"
text.split("\n").each do |line|
next if line.strip == ""
cmd, args = line.split(": ")
args = eval(args)
puts "Command: #{cmd}\nArgs: #{args.join(",")}"
result = mc.send(cmd, *args)
puts "Result: #{result} (#{mc.get(args.first).class})"
puts "\n"
end
puts "finished parsing commands"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment