Revisions

gist: 223093 Download_button fork
public
Public Clone URL: git://gist.github.com/223093.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# 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
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# 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
Text only #
1
2
3
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.
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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"