dkastner-moneta 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/lib/moneta/adapters/cassandra.rb +53 -0
- data/lib/moneta/adapters/riak.rb +53 -0
- data/lib/moneta/version.rb +1 -1
- data/spec/moneta_cassandra_spec.rb +15 -0
- data/spec/moneta_riak_spec.rb +18 -0
- metadata +13 -7
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright: 2011 TMX Credit
|
2
|
+
# Author: Potapov Sergey (aka Blake)
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "cassandra"
|
6
|
+
rescue LoadError
|
7
|
+
puts "You need the cassandra gem to use the Cassandra store"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
module Moneta
|
12
|
+
module Adapters
|
13
|
+
class Cassandra
|
14
|
+
include Defaults
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
options[:keyspace] ||= 'Moneta'
|
18
|
+
options[:host] ||= '127.0.0.1'
|
19
|
+
options[:port] ||= 9160
|
20
|
+
@client = ::Cassandra.new(options[:keyspace], "#{options[:host]}:#{options[:port]}")
|
21
|
+
@column_family = options[:column_family] || :Moneta
|
22
|
+
end
|
23
|
+
|
24
|
+
def key?(key, *)
|
25
|
+
key = key_for(key)
|
26
|
+
@client.exists?(@column_family, key)
|
27
|
+
end
|
28
|
+
|
29
|
+
def [](key)
|
30
|
+
key = key_for(key)
|
31
|
+
deserialize(@client.get(@column_family, key)['value'])
|
32
|
+
end
|
33
|
+
|
34
|
+
def delete(key, *)
|
35
|
+
key = key_for(key)
|
36
|
+
value = self[key]
|
37
|
+
@client.remove(@column_family, key)
|
38
|
+
value
|
39
|
+
end
|
40
|
+
|
41
|
+
def store(key, value, *)
|
42
|
+
key = key_for(key)
|
43
|
+
@client.insert(@column_family, key, {'value' => serialize(value)})
|
44
|
+
end
|
45
|
+
|
46
|
+
def clear(*)
|
47
|
+
@client.each_key(@column_family) do |key|
|
48
|
+
delete(key)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright: 2011 TMX Credit
|
2
|
+
# Author: Potapov Sergey (aka Blake)
|
3
|
+
|
4
|
+
begin
|
5
|
+
require "ripple"
|
6
|
+
rescue LoadError
|
7
|
+
puts "You need the ripple gem to use the Riak store"
|
8
|
+
exit
|
9
|
+
end
|
10
|
+
|
11
|
+
module Moneta
|
12
|
+
module Adapters
|
13
|
+
class Riak
|
14
|
+
include Defaults
|
15
|
+
|
16
|
+
def initialize(options = {})
|
17
|
+
bucket_name = options.delete(:bucket) || 'moneta'
|
18
|
+
client = ::Riak::Client.new(options)
|
19
|
+
@bucket = client.bucket(bucket_name)
|
20
|
+
end
|
21
|
+
|
22
|
+
def key?(key, *)
|
23
|
+
!!self[key]
|
24
|
+
end
|
25
|
+
|
26
|
+
def [](key)
|
27
|
+
serialized_key = key_for(key)
|
28
|
+
deserialize(@bucket[serialized_key].data)
|
29
|
+
rescue ::Riak::HTTPFailedRequest => err
|
30
|
+
nil
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete(key, *)
|
34
|
+
value = self[key]
|
35
|
+
serialized_key = key_for(key)
|
36
|
+
@bucket.delete(serialized_key)
|
37
|
+
value
|
38
|
+
end
|
39
|
+
|
40
|
+
def store(key, value, *)
|
41
|
+
serialized_key = key_for(key)
|
42
|
+
obj = ::Riak::RObject.new(@bucket, serialized_key)
|
43
|
+
obj.content_type = "text/plain"
|
44
|
+
obj.data = serialize(value)
|
45
|
+
obj.store
|
46
|
+
end
|
47
|
+
|
48
|
+
def clear(*)
|
49
|
+
@bucket.keys.each{|key| @bucket.delete(key)}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/moneta/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'moneta/adapters/cassandra'
|
5
|
+
|
6
|
+
describe "Moneta::Adapters::Cassandra" do
|
7
|
+
before(:each) do
|
8
|
+
@cache = Moneta::Adapters::Cassandra.new
|
9
|
+
@cache.clear
|
10
|
+
end
|
11
|
+
|
12
|
+
it_should_behave_like "a read/write Moneta cache"
|
13
|
+
end
|
14
|
+
rescue SystemExit
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require "moneta/adapters/riak"
|
5
|
+
|
6
|
+
describe "Moneta::Adapters::Riak" do
|
7
|
+
before(:all) do
|
8
|
+
@cache = Moneta::Adapters::Riak.new
|
9
|
+
end
|
10
|
+
|
11
|
+
before(:each) do
|
12
|
+
@cache.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
it_should_behave_like "a read/write Moneta cache"
|
16
|
+
end
|
17
|
+
rescue SystemExit
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dkastner-moneta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -14,7 +14,7 @@ date: 2011-02-10 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
17
|
-
requirement: &
|
17
|
+
requirement: &2157619360 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *2157619360
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: rake
|
28
|
-
requirement: &
|
28
|
+
requirement: &2157618820 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *2157618820
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: rspec
|
39
|
-
requirement: &
|
39
|
+
requirement: &2157618320 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *2157618320
|
48
48
|
description: A unified interface to key/value stores
|
49
49
|
email:
|
50
50
|
- wycats@gmail.com
|
@@ -66,6 +66,7 @@ files:
|
|
66
66
|
- lib/moneta.rb
|
67
67
|
- lib/moneta/adapters/active_record.rb
|
68
68
|
- lib/moneta/adapters/basic_file.rb
|
69
|
+
- lib/moneta/adapters/cassandra.rb
|
69
70
|
- lib/moneta/adapters/couch.rb
|
70
71
|
- lib/moneta/adapters/datamapper.rb
|
71
72
|
- lib/moneta/adapters/file.rb
|
@@ -77,6 +78,7 @@ files:
|
|
77
78
|
- lib/moneta/adapters/pstore.rb
|
78
79
|
- lib/moneta/adapters/rackspace.rb
|
79
80
|
- lib/moneta/adapters/redis.rb
|
81
|
+
- lib/moneta/adapters/riak.rb
|
80
82
|
- lib/moneta/adapters/s3.rb
|
81
83
|
- lib/moneta/adapters/sdbm.rb
|
82
84
|
- lib/moneta/adapters/tokyo_cabinet.rb
|
@@ -90,6 +92,7 @@ files:
|
|
90
92
|
- script/generate
|
91
93
|
- spec/moneta_active_record_spec.rb
|
92
94
|
- spec/moneta_basic_file_spec.rb
|
95
|
+
- spec/moneta_cassandra_spec.rb
|
93
96
|
- spec/moneta_couch_spec.rb
|
94
97
|
- spec/moneta_datamapper_spec.rb
|
95
98
|
- spec/moneta_file_spec.rb
|
@@ -100,6 +103,7 @@ files:
|
|
100
103
|
- spec/moneta_pstore_spec.rb
|
101
104
|
- spec/moneta_rackspace_spec.rb
|
102
105
|
- spec/moneta_redis_spec.rb
|
106
|
+
- spec/moneta_riak_spec.rb
|
103
107
|
- spec/moneta_s3_spec.rb
|
104
108
|
- spec/moneta_sdbm_spec.rb
|
105
109
|
- spec/moneta_tokyo_cabinet_spec.rb
|
@@ -136,6 +140,7 @@ summary: A unified interface to key/value stores, including MongoDB, Redis, Toky
|
|
136
140
|
test_files:
|
137
141
|
- spec/moneta_active_record_spec.rb
|
138
142
|
- spec/moneta_basic_file_spec.rb
|
143
|
+
- spec/moneta_cassandra_spec.rb
|
139
144
|
- spec/moneta_couch_spec.rb
|
140
145
|
- spec/moneta_datamapper_spec.rb
|
141
146
|
- spec/moneta_file_spec.rb
|
@@ -146,6 +151,7 @@ test_files:
|
|
146
151
|
- spec/moneta_pstore_spec.rb
|
147
152
|
- spec/moneta_rackspace_spec.rb
|
148
153
|
- spec/moneta_redis_spec.rb
|
154
|
+
- spec/moneta_riak_spec.rb
|
149
155
|
- spec/moneta_s3_spec.rb
|
150
156
|
- spec/moneta_sdbm_spec.rb
|
151
157
|
- spec/moneta_tokyo_cabinet_spec.rb
|