Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use nil for empty byte array, not empty string. Improves API.

  • Loading branch information...
commit 02e8957ff2edbac2dc341670f48f3a5f046612dc 1 parent 66b059f
Evan Weaver authored
View
2  CHANGELOG
@@ -1,4 +1,6 @@
+v0.2.2. Use nil for empty byte array, not empty string. Improves API.
+
v0.2.1. Don't write serialization overhead on nulls.
v0.2. Re-factor table vs. column family interface per discussion with jbellis.
View
12 lib/cassandra_client/cassandra_client.rb
@@ -147,7 +147,11 @@ def get(column_family, key, super_column = nil, column = nil, offset = -1, limit
end
rescue NotFoundException
is_super(column_family) && !column ? {} : nil
- end
+ end
+
+ # FIXME
+ # def exists?
+ # end
# FIXME
# def get_recent(column_family, key, super_column = nil, column = nil, timestamp = 0)
@@ -169,13 +173,13 @@ def count(column_family, key_range = ''..'', limit = MAX_INT)
private
def dump(object)
- # Special-case the empty string, so we don't store worthless serializer overhead on nulls
- return "" if object == ""
+ # Special-case nil as the empty byte array
+ return "" if object == nil
@serializer.dump(object)
end
def load(object)
- return "" if object == ""
+ return nil if object == ""
@serializer.load(object)
end
end
View
4 test/cassandra_client_test.rb
@@ -36,14 +36,14 @@ def test_get_key_name_sorted
def test_get_key_name_sorted_preserving_order
# In-order hash is preserved
- hash = CassandraClient::OrderedHash['a', '', 'b', '', 'c', '', 'd', '',]
+ hash = CassandraClient::OrderedHash['a', nil, 'b', nil, 'c', nil, 'd', nil,]
@twitter.insert(:Users, key, hash)
assert_equal(hash.keys, @twitter.get(:Users, key).keys)
@twitter.remove(:Users, key)
# Out-of-order hash is returned sorted
- hash = CassandraClient::OrderedHash['b', '', 'c', '', 'd', '', 'a', '']
+ hash = CassandraClient::OrderedHash['b', nil, 'c', nil, 'd', nil, 'a', nil]
@twitter.insert(:Users, key, hash)
assert_equal(hash.keys.sort, @twitter.get(:Users, key).keys)
assert_not_equal(hash.keys, @twitter.get(:Users, key).keys)
Please sign in to comment.
Something went wrong with that request. Please try again.