sessionm-cassandra_object 2.2.28 → 2.2.29

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,6 +19,18 @@ module CassandraObject
19
19
  nil
20
20
  end
21
21
 
22
+ def get_counter(key, column)
23
+ result = ActiveSupport::Notifications.instrument("get_counter.cassandra_object", column_family: column_family, key: key, column: column) do
24
+ connection.get(column_family, key, column)
25
+ end
26
+
27
+ if result
28
+ result.to_i
29
+ else
30
+ raise CassandraObject::RecordNotFound
31
+ end
32
+ end
33
+
22
34
  def all(options = {})
23
35
  limit = options[:limit] || 100
24
36
  results = ActiveSupport::Notifications.instrument("get_range.cassandra_object", column_family: column_family, key_count: limit) do
@@ -1,11 +1,23 @@
1
1
  module CassandraObject
2
2
  class LogSubscriber < ActiveSupport::LogSubscriber
3
+ def add(event)
4
+ name = '%s add (%.1fms)' % [event.payload[:column_family], event.duration]
5
+
6
+ debug " #{name} #{event.payload[:key]}[#{event.payload[:column]}]#{event.payload[:sub_column] ? '[' + event.payload[:sub_column] + ']' : ''} by #{event.payload[:value]}"
7
+ end
8
+
3
9
  def get(event)
4
10
  name = '%s get (%.1fms)' % [event.payload[:column_family], event.duration]
5
-
11
+
6
12
  debug " #{name} #{event.payload[:key]}"
7
13
  end
8
14
 
15
+ def get_counter(event)
16
+ name = '%s get_counter (%.1fms)' % [event.payload[:column_family], event.duration]
17
+
18
+ debug " #{name} #{event.payload[:key]}[#{event.payload[:column]}]"
19
+ end
20
+
9
21
  def multi_get(event)
10
22
  name = '%s multi_get (%.1fms)' % [event.payload[:column_family], event.duration]
11
23
 
@@ -3,6 +3,18 @@ module CassandraObject
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  module ClassMethods
6
+ def add(key, value, *columns_and_options)
7
+ # DataStax recommends using consistency level ONE:
8
+ # http://www.datastax.com/docs/0.8/ddl/column_family#about-column-families
9
+ defaults = Cassandra::WRITE_DEFAULTS.merge(:consistency => Cassandra::Consistency::ONE)
10
+
11
+ column_family, column, sub_column, options = connection.extract_and_validate_params(self.column_family, key, columns_and_options, defaults)
12
+
13
+ ActiveSupport::Notifications.instrument("add.cassandra_object", column_family: column_family, key: key, column: column, sub_column: sub_column, value: value) do
14
+ connection.add(column_family, key, value, *columns_and_options)
15
+ end
16
+ end
17
+
6
18
  def remove(key)
7
19
  ActiveSupport::Notifications.instrument("remove.cassandra_object", column_family: column_family, key: key) do
8
20
  connection.remove(column_family, key.to_s, consistency: thrift_write_consistency)
@@ -34,6 +34,19 @@ module CassandraObject
34
34
  connection.add_column_family(cf)
35
35
  end
36
36
 
37
+ def update(name, &block)
38
+ cf = Cassandra::ColumnFamily.new
39
+ cf.name = name.to_s
40
+ cf.keyspace = @keyspace.to_s
41
+ cf.comparator_type = 'BytesType'
42
+ cf.column_type = 'Standard'
43
+
44
+ block.call cf if block
45
+
46
+ post_process_column_family(cf)
47
+ connection.update_column_family(cf)
48
+ end
49
+
37
50
  def drop(name)
38
51
  connection.drop_column_family(name.to_s)
39
52
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'sessionm-cassandra_object'
5
- s.version = '2.2.28'
5
+ s.version = '2.2.29'
6
6
  s.description = 'Cassandra ActiveModel'
7
7
  s.summary = 'Cassandra ActiveModel'
8
8
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sessionm-cassandra_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.28
4
+ version: 2.2.29
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-10-08 00:00:00.000000000Z
14
+ date: 2011-10-28 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rails
18
- requirement: &70285832685260 !ruby/object:Gem::Requirement
18
+ requirement: &70132962539220 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,10 +23,10 @@ dependencies:
23
23
  version: '3.0'
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *70285832685260
26
+ version_requirements: *70132962539220
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: cassandra
29
- requirement: &70285832684800 !ruby/object:Gem::Requirement
29
+ requirement: &70132962538360 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ! '>='
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 0.11.3
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *70285832684800
37
+ version_requirements: *70132962538360
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: bundler
40
- requirement: &70285832684340 !ruby/object:Gem::Requirement
40
+ requirement: &70132962537780 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,7 +45,7 @@ dependencies:
45
45
  version: 1.0.0
46
46
  type: :development
47
47
  prerelease: false
48
- version_requirements: *70285832684340
48
+ version_requirements: *70132962537780
49
49
  description: Cassandra ActiveModel
50
50
  email: klange@sessionm.com
51
51
  executables: []