1

我已经开始在一个项目中使用Cequel,但我不知道如何使用 Counters 表。我有以下定义:

class Counter
  include Cequel::Record

  key :user_id, :text
  column :text, :counter
  column :int, :counter
  column :boolean, :counter
  column :timestamp, :counter
  column :tag, :counter
end

它会正确创建表格:

>> DESCRIBE counters ;

CREATE TABLE counters (
    user_id text PRIMARY KEY,
    visits counter,
    tweets counter
) WITH bloom_filter_fp_chance = 0.01
    AND caching = {'keys': 'ALL', 'rows_per_partition': 'NONE'}
    AND comment = ''
    AND compaction = {'class': 'org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy', 'max_threshold': '32', 'min_threshold': '4'}
    AND compression = {'chunk_length_in_kb': '64', 'class': 'org.apache.cassandra.io.compress.LZ4Compressor'}
    AND crc_check_chance = 1.0
    AND dclocal_read_repair_chance = 0.1
    AND default_time_to_live = 0
    AND gc_grace_seconds = 864000
    AND max_index_interval = 2048
    AND memtable_flush_period_in_ms = 0
    AND min_index_interval = 128
    AND read_repair_chance = 0.0
    AND speculative_retry = '99PERCENTILE';

但是当我尝试在控制台中创建记录时,我得到:

INSERT statements are not allowed on counter tables, use UPDATE instead

我可以在测试中看到有一种方法可以增加,但我找不到正确的语法。任何人都有设置它的经验并且可以指出我正确的方向吗?

谢谢!

4

1 回答 1

0

找不到Metal与测试中的方式不同的解决方案。在这里发帖供其他人使用,或者如果有人有更好的解决方案。

Cequel::Record.connection[COUNTERS_TABLE].where(record_id: record_id).increment(field_name: 1)
于 2017-08-01T10:56:26.890 回答