cassandra_client 0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +2 -0
- data/README +1 -1
- data/cassandra_client.gemspec +1 -1
- data/lib/cassandra_client/cassandra_client.rb +19 -8
- data/lib/cassandra_client/serialization.rb +22 -29
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
data/CHANGELOG
CHANGED
data/README
CHANGED
data/cassandra_client.gemspec
CHANGED
@@ -2,20 +2,18 @@ class CassandraClient
|
|
2
2
|
include Helper
|
3
3
|
class AccessError < StandardError; end
|
4
4
|
|
5
|
-
MAX_INT = 2**31 - 1
|
6
|
-
|
7
|
-
attr_reader :keyspace, :host, :port, :quorum, :
|
5
|
+
MAX_INT = 2**31 - 1
|
6
|
+
|
7
|
+
attr_reader :keyspace, :host, :port, :quorum, :serializer, :transport, :client, :schema
|
8
8
|
|
9
9
|
# Instantiate a new CassandraClient and open the connection.
|
10
|
-
def initialize(keyspace, host = '127.0.0.1', port = 9160, quorum = 1,
|
10
|
+
def initialize(keyspace, host = '127.0.0.1', port = 9160, quorum = 1, serializer = CassandraClient::Serialization::JSON)
|
11
11
|
@keyspace = keyspace
|
12
12
|
@host = host
|
13
13
|
@port = port
|
14
14
|
@quorum = quorum
|
15
|
-
@
|
15
|
+
@serializer = serializer
|
16
16
|
|
17
|
-
extend(@serialization)
|
18
|
-
|
19
17
|
@transport = Thrift::BufferedTransport.new(Thrift::Socket.new(@host, @port))
|
20
18
|
@transport.open
|
21
19
|
@client = Cassandra::SafeClient.new(
|
@@ -33,7 +31,7 @@ class CassandraClient
|
|
33
31
|
def inspect
|
34
32
|
"#<CassandraClient:#{object_id}, @keyspace=#{keyspace.inspect}, @schema={#{
|
35
33
|
schema.map {|name, hash| ":#{name} => #{hash['type'].inspect}"}.join(', ')
|
36
|
-
}}, @host=#{host.inspect}, @port=#{port}, @quorum=#{quorum}, @
|
34
|
+
}}, @host=#{host.inspect}, @port=#{port}, @quorum=#{quorum}, @serializer=#{serializer.name}>"
|
37
35
|
end
|
38
36
|
|
39
37
|
## Write
|
@@ -167,4 +165,17 @@ class CassandraClient
|
|
167
165
|
def count(column_family, key_range = ''..'', limit = MAX_INT)
|
168
166
|
get_key_range(column_family, key_range, limit).size
|
169
167
|
end
|
168
|
+
|
169
|
+
private
|
170
|
+
|
171
|
+
def dump(object)
|
172
|
+
# Special-case the empty string, so we don't store worthless serializer overhead on nulls
|
173
|
+
return "" if object == ""
|
174
|
+
@serializer.dump(object)
|
175
|
+
end
|
176
|
+
|
177
|
+
def load(object)
|
178
|
+
return "" if object == ""
|
179
|
+
@serializer.load(object)
|
180
|
+
end
|
170
181
|
end
|
@@ -2,63 +2,56 @@
|
|
2
2
|
class CassandraClient
|
3
3
|
module Serialization
|
4
4
|
module String
|
5
|
-
def dump(object);
|
5
|
+
def self.dump(object);
|
6
6
|
object.to_s
|
7
7
|
end
|
8
|
-
|
9
|
-
def load(object)
|
8
|
+
|
9
|
+
def self.load(object)
|
10
10
|
object
|
11
11
|
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
module Marshal
|
15
|
-
def dump(object)
|
15
|
+
def self.dump(object)
|
16
16
|
::Marshal.dump(object)
|
17
17
|
end
|
18
18
|
|
19
|
-
def load(object)
|
19
|
+
def self.load(object)
|
20
20
|
::Marshal.load(object)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
module JSON
|
25
|
-
def dump(object)
|
25
|
+
def self.dump(object)
|
26
26
|
::JSON.dump(object)
|
27
27
|
end
|
28
28
|
|
29
29
|
begin
|
30
30
|
require 'yajl/json_gem'
|
31
|
-
def load(object)
|
31
|
+
def self.load(object)
|
32
32
|
::JSON.load(object)
|
33
33
|
end
|
34
|
-
rescue LoadError
|
35
|
-
require 'json/ext'
|
36
|
-
def load(object)
|
34
|
+
rescue LoadError
|
35
|
+
require 'json/ext'
|
36
|
+
def self.load(object)
|
37
37
|
::JSON.load("[#{object}]").first # :-(
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
|
+
module CompressedJSON
|
43
|
+
def self.dump(object)
|
44
|
+
Zlib::Deflate.deflate(JSON.dump(object))
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.load(object)
|
48
|
+
JSON.load(Zlib::Inflate.inflate(object))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
42
52
|
# module Avro
|
43
53
|
# # Someday!
|
44
54
|
# end
|
45
|
-
|
46
|
-
# Decorate all available modules with compression
|
47
|
-
self.constants.each do |module_name|
|
48
|
-
eval <<-MODULE
|
49
|
-
module Compressed#{module_name}
|
50
|
-
include #{module_name}
|
51
|
-
def dump(object)
|
52
|
-
Zlib::Deflate.deflate(super(object))
|
53
|
-
end
|
54
|
-
|
55
|
-
def load(object)
|
56
|
-
super(Zlib::Inflate.inflate(object))
|
57
|
-
end
|
58
|
-
end
|
59
|
-
MODULE
|
60
|
-
end
|
61
|
-
|
62
55
|
end
|
63
56
|
end
|
64
57
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|