memcache 1.2.12 → 1.2.13

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -3,9 +3,9 @@
3
3
  This is the Geni memcached client. It started out as a fork of fiveruns/memcache-client,
4
4
  which was a fork of seattle.rb's memcache-client, but over time, our client has diverged,
5
5
  and I've rewritten the majority of the code. Of course, a lot of credit is due to those
6
- whose code served as a starting point for this code. Also, thanks to Evan Weaver for the
7
- idea to include the libmemcached source and the code to make it compile when installing
8
- the gem.
6
+ whose code served as a starting point for this code. Thanks to fauna for the idea to
7
+ include the libmemcached source and the code to make it compile when installing the
8
+ gem. Thanks to develon for the improvements to SegementedServer.
9
9
 
10
10
  == Usage
11
11
 
data/Rakefile CHANGED
@@ -59,12 +59,14 @@ Rake::RDocTask.new do |rdoc|
59
59
  rdoc.rdoc_files.include('lib/**/*.rb')
60
60
  end
61
61
 
62
- namespace :test do
62
+ namespace :test => 'lib/memcache/native_server.o' do
63
63
  Rake::TestTask.new(:native) do |t|
64
- `cd ext && make && cp native_server.bundle native_server.o ../lib/memcache/`
65
64
  t.libs << 'test'
66
65
  t.pattern = 'test/memcache_*native_server_test.rb'
67
66
  t.verbose
68
67
  end
69
68
  end
70
69
 
70
+ file 'lib/memcache/native_server.o' do
71
+ `cd ext && ruby extconf.rb && make && cp native_server.bundle native_server.o ../lib/memcache/`
72
+ end
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
- :build:
3
2
  :minor: 2
4
- :patch: 12
3
+ :patch: 13
4
+ :build:
5
5
  :major: 1
data/ext/extconf.rb CHANGED
@@ -27,7 +27,7 @@ if !ENV["EXTERNAL_LIB"]
27
27
  raise "'#{cmd}' failed" unless system(cmd)
28
28
 
29
29
  Dir.chdir(BUNDLE_PATH) do
30
- puts(cmd = "env CFLAGS='-fPIC' ./configure --prefix=#{HERE} --without-memcached --disable-shared --disable-utils --disable-dependency-tracking #{$EXTRA_CONF} 2>&1")
30
+ puts(cmd = "env CFLAGS='-fPIC' ./configure --prefix=#{HERE} --without-memcached --disable-shared --disable-utils --disable-dependency-tracking #{ARGV.join(' ')} 2>&1")
31
31
  raise "'#{cmd}' failed" unless system(cmd)
32
32
 
33
33
  puts(cmd = "make CXXFLAGS='#{$CXXFLAGS}' || true 2>&1")
data/lib/memcache.rb CHANGED
@@ -108,7 +108,7 @@ class Memcache
108
108
  raise 'opts must be hash' unless opts.instance_of?(Hash)
109
109
 
110
110
  if keys.instance_of?(Array)
111
- keys.collect! {|key| key.to_s}
111
+ keys = keys.collect {|key| key.to_s}
112
112
  multi_get(keys, opts)
113
113
  else
114
114
  key = keys.to_s
@@ -196,7 +196,8 @@ class Memcache
196
196
  end
197
197
 
198
198
  def count(key)
199
- get(key, :raw => true).to_i
199
+ value = get(key, :raw => true)
200
+ value.to_i if value
200
201
  end
201
202
 
202
203
  def incr(key, amount = 1)
@@ -262,7 +263,12 @@ class Memcache
262
263
  method = opts[:overwrite] ? :set : :add
263
264
  if keys_to_fetch.any?
264
265
  yield(keys_to_fetch).each do |key, value|
265
- self.send(method, key, value, opts) unless opts[:disable] or opts[:disable_write]
266
+ begin
267
+ self.send(method, key, value, opts) unless opts[:disable] or opts[:disable_write]
268
+ rescue Memcache::Error => e
269
+ raise if opts[:strict_write]
270
+ $stderr.puts "Memcache error in get_some: #{e.class} #{e.to_s} on key '#{key}' while storing value: #{value}"
271
+ end
266
272
  records[key] = value
267
273
  end
268
274
  end
@@ -414,7 +420,7 @@ protected
414
420
  object.memcache_cas = value.memcache_cas
415
421
  object
416
422
  rescue Exception => e
417
- puts "Memcache read error: #{e.class} #{e.to_s} on key '#{key}' while unmarshalling value: #{value}"
423
+ $stderr.puts "Memcache read error: #{e.class} #{e.to_s} on key '#{key}' while unmarshalling value: #{value}"
418
424
  nil
419
425
  end
420
426
 
@@ -14,13 +14,8 @@ class Memcache
14
14
  keys_to_fetch = []
15
15
  results.each do |key, value|
16
16
  next unless segmented?(value)
17
- hash, num = value.split(':')
18
- keys[key] = []
19
- num.to_i.times do |i|
20
- hash_key = "#{hash}:#{i}"
21
- keys_to_fetch << hash_key
22
- keys[key] << hash_key
23
- end
17
+ keys[key] = segment_keys(value)
18
+ keys_to_fetch.concat keys[key]
24
19
  end
25
20
 
26
21
  parts = super(keys_to_fetch)
@@ -45,13 +40,17 @@ class Memcache
45
40
  end
46
41
 
47
42
  def set(key, value, expiry = 0, flags = 0)
48
- hash, flags = store_segments(key, value, expiry, flags)
49
- super(key, hash, expiry, flags) && value
43
+ delete(key) do
44
+ hash, flags = store_segments(key, value, expiry, flags)
45
+ super(key, hash, expiry, flags) && value
46
+ end
50
47
  end
51
48
 
52
49
  def cas(key, value, cas, expiry = 0, flags = 0)
53
- hash, flags = store_segments(key, value, expiry, flags)
54
- super(key, hash, cas, expiry, flags) && value
50
+ delete(key) do
51
+ hash, flags = store_segments(key, value, expiry, flags)
52
+ super(key, hash, cas, expiry, flags) && value
53
+ end
55
54
  end
56
55
 
57
56
  def add(key, value, expiry = 0, flags = 0)
@@ -60,8 +59,19 @@ class Memcache
60
59
  end
61
60
 
62
61
  def replace(key, value, expiry = 0, flags = 0)
63
- hash, flags = store_segments(key, value, expiry, flags)
64
- super(key, hash, expiry, flags) && value
62
+ delete(key) do
63
+ hash, flags = store_segments(key, value, expiry, flags)
64
+ super(key, hash, expiry, flags) && value
65
+ end
66
+ end
67
+
68
+ def delete(key)
69
+ value = super_get(key)
70
+ result = block_given? ? yield : super
71
+ if result and segmented?(value)
72
+ segment_keys(value).each {|k| super(k)}
73
+ end
74
+ result
65
75
  end
66
76
 
67
77
  private
@@ -94,6 +104,18 @@ class Memcache
94
104
  [value, flags]
95
105
  end
96
106
  end
107
+
108
+ def segment_keys(value)
109
+ hash, num = value.split(':')
110
+ (0...num.to_i).collect {|i| "#{hash}:#{i}"}
111
+ end
112
+
113
+ def self.included(klass)
114
+ super_get = klass.ancestors[2].instance_method(:get)
115
+ klass.send(:define_method, :super_get) do |key|
116
+ super_get.bind(self).call([key])[key]
117
+ end
118
+ end
97
119
  end
98
120
 
99
121
  class SegmentedServer < Server
@@ -216,7 +216,7 @@ class Memcache
216
216
  end
217
217
 
218
218
  def read_command(command, &block)
219
- raise ConnectionError, "Server dead, will retry at #{retry_at}" unless alive?
219
+ raise ConnectionError, "Server #{name} dead, will retry at #{retry_at}" unless alive?
220
220
  send_command(command) do |response|
221
221
  while response do
222
222
  return if response == "END\r\n"
data/memcache.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{memcache}
8
- s.version = "1.2.12"
8
+ s.version = "1.2.13"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Justin Balthrop"]
12
- s.date = %q{2010-05-10}
12
+ s.date = %q{2010-08-31}
13
13
  s.description = %q{Ruby client for memcached supporting advanced protocol features and pluggable architecture.}
14
14
  s.email = %q{code@justinbalthrop.com}
15
15
  s.extensions = ["ext/extconf.rb"]
@@ -43,6 +43,7 @@ Gem::Specification.new do |s|
43
43
  "test/memcache_pg_server_test.rb",
44
44
  "test/memcache_segmented_native_server_test.rb",
45
45
  "test/memcache_segmented_server_test.rb",
46
+ "test/memcache_segmented_test_helper.rb",
46
47
  "test/memcache_server_test.rb",
47
48
  "test/memcache_server_test_helper.rb",
48
49
  "test/memcache_test.rb",
@@ -51,7 +52,7 @@ Gem::Specification.new do |s|
51
52
  s.homepage = %q{http://github.com/ninjudd/memcache}
52
53
  s.rdoc_options = ["--charset=UTF-8"]
53
54
  s.require_paths = ["lib"]
54
- s.rubygems_version = %q{1.3.5}
55
+ s.rubygems_version = %q{1.3.7}
55
56
  s.summary = %q{Advanced ruby memcache client}
56
57
  s.test_files = [
57
58
  "test/memcache_local_server_test.rb",
@@ -60,6 +61,7 @@ Gem::Specification.new do |s|
60
61
  "test/memcache_pg_server_test.rb",
61
62
  "test/memcache_segmented_native_server_test.rb",
62
63
  "test/memcache_segmented_server_test.rb",
64
+ "test/memcache_segmented_test_helper.rb",
63
65
  "test/memcache_server_test.rb",
64
66
  "test/memcache_server_test_helper.rb",
65
67
  "test/memcache_test.rb",
@@ -70,7 +72,7 @@ Gem::Specification.new do |s|
70
72
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
71
73
  s.specification_version = 3
72
74
 
73
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
75
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
74
76
  else
75
77
  end
76
78
  else
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require File.dirname(__FILE__) + '/memcache_server_test_helper'
3
+ require File.dirname(__FILE__) + '/memcache_segmented_test_helper'
3
4
 
4
5
  $VERBOSE = nil
5
6
  Memcache::Segmented.const_set('MAX_SIZE', 3)
@@ -7,6 +8,7 @@ Memcache::Segmented.const_set('MAX_SIZE', 3)
7
8
  class MemcacheSegmentedNativeServerTest < Test::Unit::TestCase
8
9
  include MemcacheServerTestHelper
9
10
  include MemcacheServerTestHelper::AdvancedMethods
11
+ include MemcacheSegmentedTestHelper
10
12
  with_prefixes nil, "foo:", "bar:"
11
13
 
12
14
  PORTS = [11212, 11213, 11214]
@@ -1,5 +1,6 @@
1
1
  require 'test/unit'
2
2
  require File.dirname(__FILE__) + '/memcache_server_test_helper'
3
+ require File.dirname(__FILE__) + '/memcache_segmented_test_helper'
3
4
 
4
5
  $VERBOSE = nil
5
6
  Memcache::Segmented.const_set('MAX_SIZE', 3)
@@ -7,6 +8,8 @@ Memcache::Segmented.const_set('MAX_SIZE', 3)
7
8
  class MemcacheSegmentedServerTest < Test::Unit::TestCase
8
9
  include MemcacheServerTestHelper
9
10
  include MemcacheServerTestHelper::AdvancedMethods
11
+ include MemcacheSegmentedTestHelper
12
+
10
13
  with_prefixes nil, "foo:", "bar:"
11
14
 
12
15
  PORT = 11212
@@ -0,0 +1,19 @@
1
+ module MemcacheSegmentedTestHelper
2
+ def test_segmented_delete
3
+ m.set('fav_numbers', '1,2,3,4,5,6,7,8,9,10')
4
+
5
+ master_key = m.send(:super_get, 'fav_numbers')
6
+ segment_keys = m.send(:segment_keys, master_key)
7
+
8
+ assert_not_equal '1,2,3,4,5,6,7,8,9,10', master_key
9
+ assert_equal 7, segment_keys.size
10
+
11
+ assert_equal '1,2,3,4,5,6,7,8,9,10', m.get('fav_numbers')
12
+ assert_equal true, m.delete('fav_numbers')
13
+ assert_equal nil, m.get('fav_numbers')
14
+
15
+ segment_keys.each do |k|
16
+ assert_equal nil, m.get(k)
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: memcache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.12
4
+ hash: 5
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 13
10
+ version: 1.2.13
5
11
  platform: ruby
6
12
  authors:
7
13
  - Justin Balthrop
@@ -9,7 +15,7 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2010-05-10 00:00:00 -07:00
18
+ date: 2010-08-31 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies: []
15
21
 
@@ -48,6 +54,7 @@ files:
48
54
  - test/memcache_pg_server_test.rb
49
55
  - test/memcache_segmented_native_server_test.rb
50
56
  - test/memcache_segmented_server_test.rb
57
+ - test/memcache_segmented_test_helper.rb
51
58
  - test/memcache_server_test.rb
52
59
  - test/memcache_server_test_helper.rb
53
60
  - test/memcache_test.rb
@@ -62,21 +69,27 @@ rdoc_options:
62
69
  require_paths:
63
70
  - lib
64
71
  required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
65
73
  requirements:
66
74
  - - ">="
67
75
  - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
68
79
  version: "0"
69
- version:
70
80
  required_rubygems_version: !ruby/object:Gem::Requirement
81
+ none: false
71
82
  requirements:
72
83
  - - ">="
73
84
  - !ruby/object:Gem::Version
85
+ hash: 3
86
+ segments:
87
+ - 0
74
88
  version: "0"
75
- version:
76
89
  requirements: []
77
90
 
78
91
  rubyforge_project:
79
- rubygems_version: 1.3.5
92
+ rubygems_version: 1.3.7
80
93
  signing_key:
81
94
  specification_version: 3
82
95
  summary: Advanced ruby memcache client
@@ -87,6 +100,7 @@ test_files:
87
100
  - test/memcache_pg_server_test.rb
88
101
  - test/memcache_segmented_native_server_test.rb
89
102
  - test/memcache_segmented_server_test.rb
103
+ - test/memcache_segmented_test_helper.rb
90
104
  - test/memcache_server_test.rb
91
105
  - test/memcache_server_test_helper.rb
92
106
  - test/memcache_test.rb