我已经开始在项目中使用Cequel,但我无法弄清楚如何使用计数器表。我有以下定义:
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
我可以在tests中看到有增加的方法,但我无法找到正确的语法。任何人都有这方面的经验,可以指出我正确的方向吗?
谢谢!
答案 0 :(得分:0)
无法在测试中找到与Metal
方式不同的解决方案。在此发布供其他人使用或有人有更好的解决方案。
Cequel::Record.connection[COUNTERS_TABLE].where(record_id: record_id).increment(field_name: 1)