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 CHANGED
@@ -1,4 +1,6 @@
1
1
 
2
+ v0.2.1. Don't write serialization overhead on nulls.
3
+
2
4
  v0.2. Re-factor table vs. column family interface per discussion with jbellis.
3
5
 
4
6
  v0.1. First release.
data/README CHANGED
@@ -55,7 +55,7 @@ Query a super column:
55
55
 
56
56
  The returned result will always be a CassandraClient::OrderedHash.
57
57
 
58
- See CassandraClient and CassandraClient::Table for more methods.
58
+ See CassandraClient for more methods.
59
59
 
60
60
  == Reporting problems
61
61
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{cassandra_client}
5
- s.version = "0.2"
5
+ s.version = "0.2.1"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0.8") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Evan Weaver"]
@@ -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, :serialization, :transport, :client, :schema
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, serialization = CassandraClient::Serialization::JSON)
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
- @serialization = serialization
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}, @serialization=#{serialization.name}>"
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cassandra_client
3
3
  version: !ruby/object:Gem::Version
4
- version: "0.2"
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Evan Weaver
metadata.gz.sig CHANGED
Binary file