remcached 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 3
3
- :patch: 1
2
+ :minor: 4
3
+ :patch: 0
4
4
  :major: 0
data/examples/fill.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  # Experimentally determine how many items fit in your memcached
4
4
  # instance. Adjust parameters below for your scenario.
5
5
 
6
- BATCH_SIZE = 1000
7
- KEY_SIZE = 20
8
- VALUE_SIZE = 20
6
+ BATCH_SIZE = 10000
7
+ KEY_SIZE = 26
8
+ VALUE_SIZE = 0
9
9
 
10
10
 
11
11
  $: << File.dirname(__FILE__) + "/../lib"
@@ -28,27 +28,45 @@ module Memcached
28
28
  @recv_buf = ""
29
29
  @recv_state = :header
30
30
  @connected = false
31
+ @keepalive_timer = nil
31
32
  end
32
33
 
33
34
  def connection_completed
34
35
  @connected = true
35
36
  @connect_deferrable.succeed(self)
37
+
38
+ @last_receive = Time.now
39
+ @keepalive_timer = EventMachine::PeriodicTimer.new(1, &method(:keepalive))
36
40
  end
37
41
 
38
42
  RECONNECT_DELAY = 10
39
43
  RECONNECT_JITTER = 5
40
44
  def unbind
45
+ @keepalive_timer.cancel if @keepalive_timer
46
+
41
47
  @connected = false
42
48
  EventMachine::Timer.new(RECONNECT_DELAY + rand(RECONNECT_JITTER),
43
49
  method(:reconnect))
44
50
  end
45
51
 
52
+ RECEIVE_TIMEOUT = 15
53
+ KEEPALIVE_INTERVAL = 5
54
+ def keepalive
55
+ if @last_receive + RECEIVE_TIMEOUT <= Time.now
56
+ p :timeout
57
+ close_connection
58
+ elsif @last_receive + KEEPALIVE_INTERVAL <= Time.now
59
+ send_keepalive
60
+ end
61
+ end
62
+
46
63
  def send_packet(pkt)
47
64
  send_data pkt.to_s
48
65
  end
49
66
 
50
67
  def receive_data(data)
51
68
  @recv_buf += data
69
+ @last_receive = Time.now
52
70
 
53
71
  done = false
54
72
  while not done
@@ -129,6 +147,10 @@ module Memcached
129
147
  end
130
148
  end
131
149
 
150
+ def send_keepalive
151
+ send_request Request::NoOp.new
152
+ end
153
+
132
154
  # Callback will be called multiple times
133
155
  def stats(contents={}, &callback)
134
156
  send_request Request::Stats.new(contents) do |result|
@@ -29,6 +29,7 @@ module Memcached
29
29
  SETQ = 0x11
30
30
  ADDQ = 0x12
31
31
  DELETEQ = 0x14
32
+ NOOP = 0x0a
32
33
 
33
34
  =begin
34
35
  Possible values of the one-byte field:
@@ -235,6 +235,12 @@ module Memcached
235
235
  super({:opcode=>Commands::STAT}.merge(contents))
236
236
  end
237
237
  end
238
+
239
+ class NoOp < Request
240
+ def initialize
241
+ super(:opcode=>Commands::NOOP)
242
+ end
243
+ end
238
244
  end
239
245
 
240
246
  ##
data/remcached.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{remcached}
8
- s.version = "0.3.1"
8
+ s.version = "0.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stephan Maka"]
12
- s.date = %q{2009-10-12}
12
+ s.date = %q{2009-10-14}
13
13
  s.description = %q{Ruby EventMachine memcached client}
14
14
  s.email = %q{astro@spaceboyz.net}
15
15
  s.extra_rdoc_files = [
@@ -37,9 +37,9 @@ Gem::Specification.new do |s|
37
37
  s.rubygems_version = %q{1.3.5}
38
38
  s.summary = %q{Ruby EventMachine memcached client}
39
39
  s.test_files = [
40
- "spec/client_spec.rb",
41
- "spec/memcached_spec.rb",
40
+ "spec/memcached_spec.rb",
42
41
  "spec/packet_spec.rb",
42
+ "spec/client_spec.rb",
43
43
  "examples/fill.rb"
44
44
  ]
45
45
 
data/spec/client_spec.rb CHANGED
@@ -33,4 +33,14 @@ describe Memcached::Client do
33
33
  @stats.should include(*%w(pid uptime time version curr_connections total_connections))
34
34
  end
35
35
  end
36
+
37
+ =begin
38
+ it "should keep alive" do
39
+ run do
40
+ EM::Timer.new(30) do
41
+ stop
42
+ end
43
+ end
44
+ end
45
+ =end
36
46
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remcached
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephan Maka
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-12 00:00:00 +02:00
12
+ date: 2009-10-14 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -65,7 +65,7 @@ signing_key:
65
65
  specification_version: 3
66
66
  summary: Ruby EventMachine memcached client
67
67
  test_files:
68
- - spec/client_spec.rb
69
68
  - spec/memcached_spec.rb
70
69
  - spec/packet_spec.rb
70
+ - spec/client_spec.rb
71
71
  - examples/fill.rb