riak-client 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,56 @@
|
|
1
|
+
# Copyright 2010 Sean Cribbs, Sonian Inc., and Basho Technologies, Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License
|
14
|
+
require 'riak/util/escape'
|
15
|
+
require 'riak/json'
|
16
|
+
|
17
|
+
module Riak
|
18
|
+
class Client
|
19
|
+
class HTTPBackend
|
20
|
+
# @private
|
21
|
+
class KeyStreamer
|
22
|
+
include Util::Escape
|
23
|
+
|
24
|
+
def initialize(block)
|
25
|
+
@buffer = ""
|
26
|
+
@block = block
|
27
|
+
end
|
28
|
+
|
29
|
+
def accept(chunk)
|
30
|
+
@buffer << chunk
|
31
|
+
consume
|
32
|
+
end
|
33
|
+
|
34
|
+
def to_proc
|
35
|
+
method(:accept).to_proc
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def consume
|
40
|
+
while @buffer =~ /\}\{/
|
41
|
+
stream($~.pre_match + '}')
|
42
|
+
@buffer = '{' + $~.post_match
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def stream(str)
|
47
|
+
obj = JSON.parse(str) rescue nil
|
48
|
+
if obj && obj['keys']
|
49
|
+
@block.call obj['keys'].map(&method(:unescape))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -23,6 +23,7 @@ require 'riak/robject'
|
|
23
23
|
require 'riak/client/http_backend/transport_methods'
|
24
24
|
require 'riak/client/http_backend/object_methods'
|
25
25
|
require 'riak/client/http_backend/configuration'
|
26
|
+
require 'riak/client/http_backend/key_streamer'
|
26
27
|
|
27
28
|
module Riak
|
28
29
|
class Client
|
@@ -142,12 +143,8 @@ module Riak
|
|
142
143
|
# @return [Array<String>] the list of keys, if no block was given
|
143
144
|
def list_keys(bucket, &block)
|
144
145
|
bucket = bucket.name if Bucket === bucket
|
145
|
-
if block_given?
|
146
|
-
get(200, riak_kv_wm_raw, escape(bucket), {:props => false, :keys => 'stream'}, {})
|
147
|
-
obj = JSON.parse(chunk) rescue nil
|
148
|
-
next unless obj && obj['keys']
|
149
|
-
yield obj['keys'].map {|k| unescape(k) }
|
150
|
-
end
|
146
|
+
if block_given?
|
147
|
+
get(200, riak_kv_wm_raw, escape(bucket), {:props => false, :keys => 'stream'}, {}, &KeyStreamer.new(block))
|
151
148
|
else
|
152
149
|
response = get(200, riak_kv_wm_raw, escape(bucket), {:props => false, :keys => true}, {})
|
153
150
|
obj = JSON.parse(response[:body])
|
data/lib/riak/core_ext/blank.rb
CHANGED
data/riak-client.gemspec
CHANGED
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{riak-client}
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Sean Cribbs"]
|
9
|
-
s.date = %q{2011-04-
|
9
|
+
s.date = %q{2011-04-18}
|
10
10
|
s.description = %q{riak-client is a rich client for Riak, the distributed database by Basho. It supports the full HTTP interface including storage operations, bucket configuration, link-walking and map-reduce.}
|
11
11
|
s.email = %q{sean@basho.com}
|
12
|
-
s.files = ["erl_src/riak_kv_test_backend.beam", "erl_src/riak_kv_test_backend.erl", "Gemfile", "lib/active_support/cache/riak_store.rb", "lib/riak/bucket.rb", "lib/riak/cache_store.rb", "lib/riak/client/beefcake/messages.rb", "lib/riak/client/beefcake/object_methods.rb", "lib/riak/client/beefcake_protobuffs_backend.rb", "lib/riak/client/curb_backend.rb", "lib/riak/client/excon_backend.rb", "lib/riak/client/http_backend/configuration.rb", "lib/riak/client/http_backend/object_methods.rb", "lib/riak/client/http_backend/request_headers.rb", "lib/riak/client/http_backend/transport_methods.rb", "lib/riak/client/http_backend.rb", "lib/riak/client/net_http_backend.rb", "lib/riak/client/protobuffs_backend.rb", "lib/riak/client/pump.rb", "lib/riak/client.rb", "lib/riak/core_ext/blank.rb", "lib/riak/core_ext/extract_options.rb", "lib/riak/core_ext/slice.rb", "lib/riak/core_ext/stringify_keys.rb", "lib/riak/core_ext/symbolize_keys.rb", "lib/riak/core_ext/to_param.rb", "lib/riak/core_ext.rb", "lib/riak/failed_request.rb", "lib/riak/i18n.rb", "lib/riak/json.rb", "lib/riak/link.rb", "lib/riak/locale/en.yml", "lib/riak/map_reduce/filter_builder.rb", "lib/riak/map_reduce/phase.rb", "lib/riak/map_reduce.rb", "lib/riak/map_reduce_error.rb", "lib/riak/robject.rb", "lib/riak/search.rb", "lib/riak/test_server.rb", "lib/riak/util/escape.rb", "lib/riak/util/fiber1.8.rb", "lib/riak/util/headers.rb", "lib/riak/util/multipart/stream_parser.rb", "lib/riak/util/multipart.rb", "lib/riak/util/tcp_socket_extensions.rb", "lib/riak/util/translation.rb", "lib/riak/walk_spec.rb", "lib/riak.rb", "Rakefile", "riak-client.gemspec", "spec/fixtures/cat.jpg", "spec/fixtures/multipart-blank.txt", "spec/fixtures/multipart-mapreduce.txt", "spec/fixtures/multipart-with-body.txt", "spec/fixtures/server.cert.crt", "spec/fixtures/server.cert.key", "spec/fixtures/test.pem", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/curb_backend_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb", "spec/spec_helper.rb", "spec/support/drb_mock_server.rb", "spec/support/http_backend_implementation_examples.rb", "spec/support/mock_server.rb", "spec/support/mocks.rb", "spec/support/test_server.yml.example", "spec/support/unified_backend_examples.rb"]
|
12
|
+
s.files = ["erl_src/riak_kv_test_backend.beam", "erl_src/riak_kv_test_backend.erl", "Gemfile", "lib/active_support/cache/riak_store.rb", "lib/riak/bucket.rb", "lib/riak/cache_store.rb", "lib/riak/client/beefcake/messages.rb", "lib/riak/client/beefcake/object_methods.rb", "lib/riak/client/beefcake_protobuffs_backend.rb", "lib/riak/client/curb_backend.rb", "lib/riak/client/excon_backend.rb", "lib/riak/client/http_backend/configuration.rb", "lib/riak/client/http_backend/key_streamer.rb", "lib/riak/client/http_backend/object_methods.rb", "lib/riak/client/http_backend/request_headers.rb", "lib/riak/client/http_backend/transport_methods.rb", "lib/riak/client/http_backend.rb", "lib/riak/client/net_http_backend.rb", "lib/riak/client/protobuffs_backend.rb", "lib/riak/client/pump.rb", "lib/riak/client.rb", "lib/riak/core_ext/blank.rb", "lib/riak/core_ext/extract_options.rb", "lib/riak/core_ext/slice.rb", "lib/riak/core_ext/stringify_keys.rb", "lib/riak/core_ext/symbolize_keys.rb", "lib/riak/core_ext/to_param.rb", "lib/riak/core_ext.rb", "lib/riak/failed_request.rb", "lib/riak/i18n.rb", "lib/riak/json.rb", "lib/riak/link.rb", "lib/riak/locale/en.yml", "lib/riak/map_reduce/filter_builder.rb", "lib/riak/map_reduce/phase.rb", "lib/riak/map_reduce.rb", "lib/riak/map_reduce_error.rb", "lib/riak/robject.rb", "lib/riak/search.rb", "lib/riak/test_server.rb", "lib/riak/util/escape.rb", "lib/riak/util/fiber1.8.rb", "lib/riak/util/headers.rb", "lib/riak/util/multipart/stream_parser.rb", "lib/riak/util/multipart.rb", "lib/riak/util/tcp_socket_extensions.rb", "lib/riak/util/translation.rb", "lib/riak/walk_spec.rb", "lib/riak.rb", "Rakefile", "riak-client.gemspec", "spec/fixtures/cat.jpg", "spec/fixtures/multipart-blank.txt", "spec/fixtures/multipart-mapreduce.txt", "spec/fixtures/multipart-with-body.txt", "spec/fixtures/server.cert.crt", "spec/fixtures/server.cert.key", "spec/fixtures/test.pem", "spec/integration/riak/cache_store_spec.rb", "spec/integration/riak/http_backends_spec.rb", "spec/integration/riak/protobuffs_backends_spec.rb", "spec/integration/riak/test_server_spec.rb", "spec/riak/bucket_spec.rb", "spec/riak/client_spec.rb", "spec/riak/curb_backend_spec.rb", "spec/riak/escape_spec.rb", "spec/riak/excon_backend_spec.rb", "spec/riak/headers_spec.rb", "spec/riak/http_backend/configuration_spec.rb", "spec/riak/http_backend/object_methods_spec.rb", "spec/riak/http_backend/transport_methods_spec.rb", "spec/riak/http_backend_spec.rb", "spec/riak/link_spec.rb", "spec/riak/map_reduce/filter_builder_spec.rb", "spec/riak/map_reduce/phase_spec.rb", "spec/riak/map_reduce_spec.rb", "spec/riak/multipart_spec.rb", "spec/riak/net_http_backend_spec.rb", "spec/riak/robject_spec.rb", "spec/riak/search_spec.rb", "spec/riak/stream_parser_spec.rb", "spec/riak/walk_spec_spec.rb", "spec/spec_helper.rb", "spec/support/drb_mock_server.rb", "spec/support/http_backend_implementation_examples.rb", "spec/support/mock_server.rb", "spec/support/mocks.rb", "spec/support/test_server.yml.example", "spec/support/unified_backend_examples.rb"]
|
13
13
|
s.homepage = %q{http://seancribbs.github.com/ripple}
|
14
14
|
s.require_paths = ["lib"]
|
15
15
|
s.rubygems_version = %q{1.7.2}
|
data/spec/riak/robject_spec.rb
CHANGED
@@ -73,11 +73,11 @@ describe Riak::RObject do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
it "should serialize into a YAML stream" do
|
76
|
-
@object.serialize({"foo" => "bar"}).should == "
|
76
|
+
@object.serialize({"foo" => "bar"}).should == YAML.dump({"foo" => "bar"})
|
77
77
|
end
|
78
78
|
|
79
79
|
it "should deserialize a YAML stream" do
|
80
|
-
@object.deserialize("
|
80
|
+
@object.deserialize(YAML.dump({"foo" => "bar"})).should == {"foo" => "bar"}
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
@@ -168,7 +168,20 @@ shared_examples_for "Unified backend API" do
|
|
168
168
|
@backend.list_keys("test").should == ["keys"]
|
169
169
|
end
|
170
170
|
|
171
|
-
context "streaming through a block" do
|
171
|
+
context "streaming through a block" do
|
172
|
+
it "should handle a large number of keys" do
|
173
|
+
obj = Riak::RObject.new(@client.bucket("test"))
|
174
|
+
obj.content_type = "application/json"
|
175
|
+
obj.data = [1]
|
176
|
+
750.times do |i|
|
177
|
+
obj.key = i.to_s
|
178
|
+
obj.store(:w => 1, :dw => 0, :returnbody => false)
|
179
|
+
end
|
180
|
+
@backend.list_keys("test") do |keys|
|
181
|
+
keys.should be_all {|k| k == 'keys' || (0..749).include?(k.to_i) }
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
172
185
|
it "should pass an array of keys to the block" do
|
173
186
|
@backend.list_keys("test") do |keys|
|
174
187
|
keys.should == ["keys"] unless keys.empty?
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: riak-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.9.
|
5
|
+
version: 0.9.3
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Sean Cribbs
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-04-
|
13
|
+
date: 2011-04-18 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- lib/riak/client/curb_backend.rb
|
122
122
|
- lib/riak/client/excon_backend.rb
|
123
123
|
- lib/riak/client/http_backend/configuration.rb
|
124
|
+
- lib/riak/client/http_backend/key_streamer.rb
|
124
125
|
- lib/riak/client/http_backend/object_methods.rb
|
125
126
|
- lib/riak/client/http_backend/request_headers.rb
|
126
127
|
- lib/riak/client/http_backend/transport_methods.rb
|