em-couchbase 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.markdown CHANGED
@@ -1,3 +1,8 @@
1
+ ## 0.2.0 / 2012-07-24
2
+
3
+ * Support INCR and DECR commands
4
+ * Change ruby-debug dependency to debugger
5
+
1
6
  ## 0.1.0 / 2012-03-27
2
7
 
3
8
  * Client bootstrap
data/README.markdown CHANGED
@@ -13,5 +13,12 @@ Like any Deferrable eventmachine-based protocol implementation, using EM-Couchba
13
13
  end
14
14
  end
15
15
  end
16
+ couchbase.incr "bar", :initial => 100500 do |response|
17
+ if response.success?
18
+ couchbase.get "bar" do |response|
19
+ puts response.inspect
20
+ EM.stop
21
+ end
22
+ end
23
+ end
16
24
  end
17
-
data/em-couchbase.gemspec CHANGED
@@ -44,5 +44,5 @@ Gem::Specification.new do |s|
44
44
  s.add_development_dependency 'minitest'
45
45
  s.add_development_dependency 'rdiscount'
46
46
  s.add_development_dependency 'yard'
47
- s.add_development_dependency RUBY_VERSION =~ /^1\.9/ ? 'ruby-debug19' : 'ruby-debug'
47
+ s.add_development_dependency 'debugger'
48
48
  end
@@ -164,6 +164,28 @@ module EventMachine
164
164
  end
165
165
  end
166
166
 
167
+ def incr(key, options = {}, &block)
168
+ callback do
169
+ opaque = opaque_inc
170
+ register_handler(opaque, key, block)
171
+ vbucket, node = locate(key)
172
+ node.callback do
173
+ node.arithm(:incr, opaque, vbucket, key, options)
174
+ end
175
+ end
176
+ end
177
+
178
+ def decr(key, options = {}, &block)
179
+ callback do
180
+ opaque = opaque_inc
181
+ register_handler(opaque, key, block)
182
+ vbucket, node = locate(key)
183
+ node.callback do
184
+ node.arithm(:decr, opaque, vbucket, key, options)
185
+ end
186
+ end
187
+ end
188
+
167
189
  protected
168
190
 
169
191
  def unbind
@@ -71,6 +71,20 @@ module EventMachine
71
71
  send_data(packet)
72
72
  end
73
73
 
74
+ def arithm(opcode, opaque, vbucket, key, options = {})
75
+ if options.is_a?(Fixnum)
76
+ options = {:delta => options}
77
+ end
78
+ packet = Packet.build(opaque, vbucket,
79
+ opcode, key,
80
+ options[:delta],
81
+ options[:initial],
82
+ options[:expiration],
83
+ options[:cas])
84
+ client.register_packet(opaque, packet)
85
+ send_data(packet)
86
+ end
87
+
74
88
  # @param opaque [Fixnum]
75
89
  # @param pairs [Array] array of tuples +[opaque, vbucket, key]+
76
90
  # @param options [Hash]
@@ -117,6 +117,29 @@ module EventMachine
117
117
  0, # uint64_t cas
118
118
  key
119
119
  ].pack("#{REQUEST_HEADER_FMT}a*")
120
+ when :incr, :decr
121
+ cmd_id = opcode == :incr ? CMD_INCREMENT : CMD_DECREMENT
122
+ key, delta, initial, expiration, cas = args.shift(5)
123
+ delta ||= 1
124
+ initial ||= 0
125
+ bodylen = key.size + 20
126
+ [
127
+ 0x80, # uint8_t magic
128
+ cmd_id, # uint8_t opcode
129
+ key.size, # uint16_t keylen
130
+ 20, # uint8_t extlen (delta + initial + expiration)
131
+ 0, # uint8_t datatype
132
+ vbucket, # uint16_t vbucket
133
+ bodylen, # uint32_t bodylen
134
+ opaque || 0, # uint32_t opaque
135
+ cas || 0, # uint64_t cas
136
+ delta >> 32, # uint64_t
137
+ delta & 0xffffffff, #
138
+ initial >> 32, # uint64_t
139
+ initial & 0xffffffff, #
140
+ expiration || 0, # uint32_t
141
+ key
142
+ ].pack("#{REQUEST_HEADER_FMT}NNNNNa*")
120
143
  when :sasl_auth
121
144
  mech, username, password = args.shift(3)
122
145
  value = "\0#{username}\0#{password}"
@@ -185,6 +208,14 @@ module EventMachine
185
208
  when CMD_GET
186
209
  result.operation = :get
187
210
  result.flags, _ = ext.unpack("N")
211
+ when CMD_INCREMENT
212
+ result.operation = :incr
213
+ hi, lo = result.value.unpack("NN")
214
+ result.value = hi << 32 | lo
215
+ when CMD_DECREMENT
216
+ result.operation = :decr
217
+ hi, lo = result.value.unpack("NN")
218
+ result.value = hi << 32 | lo
188
219
  else
189
220
  raise Couchbase::Error::UnknownCommand, header.inspect
190
221
  end
@@ -19,7 +19,7 @@ module EventMachine
19
19
  module Protocols
20
20
 
21
21
  module Couchbase
22
- VERSION = "0.1.0"
22
+ VERSION = "0.2.0"
23
23
  end
24
24
 
25
25
  end
data/tasks/package.rake CHANGED
@@ -22,7 +22,6 @@ def gemspec
22
22
  end
23
23
 
24
24
  Gem::PackageTask.new(gemspec) do |pkg|
25
- pkg.need_zip = true
26
25
  pkg.need_tar = true
27
26
  end
28
27
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-couchbase
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-27 00:00:00.000000000Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: yajl-ruby
@@ -124,7 +124,7 @@ dependencies:
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  - !ruby/object:Gem::Dependency
127
- name: ruby-debug19
127
+ name: debugger
128
128
  requirement: !ruby/object:Gem::Requirement
129
129
  none: false
130
130
  requirements:
@@ -180,15 +180,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
180
180
  - - ! '>='
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
+ segments:
184
+ - 0
185
+ hash: -2179491477963785270
183
186
  required_rubygems_version: !ruby/object:Gem::Requirement
184
187
  none: false
185
188
  requirements:
186
189
  - - ! '>='
187
190
  - !ruby/object:Gem::Version
188
191
  version: '0'
192
+ segments:
193
+ - 0
194
+ hash: -2179491477963785270
189
195
  requirements: []
190
196
  rubyforge_project:
191
- rubygems_version: 1.8.18
197
+ rubygems_version: 1.8.24
192
198
  signing_key:
193
199
  specification_version: 3
194
200
  summary: An EventMachine-based Couchbase ruby driver