Storing a list of values in Cassandra

后端 未结 3 1039
感情败类
感情败类 2021-01-13 08:46

Version Dependent

Some of the answers to this question deal with older versions of Cassandra. The correct answer for this kind of problem depends on the version of

3条回答
  •  -上瘾入骨i
    2021-01-13 08:58

    This answer dates to before the release of Cassandra version 1.2, which provided substantially different functionality for handling lists. The answer might be inappropriate if you are using Cassandra 1.2+.


    I would encode lists in the column key, using composite columns with the real column name as the first dimension, ie:

    row_key -> {
         [column_name; entry1] -> "",
         [column_name; entry2] -> "",
         ... 
    }
    

    Then, to read the list, you would need to do a get_slice from [column_name; ] to [column_name; ] - note the empty dimensions.

    The great thing about this is it actually implements a set quite nicely; the list cannot contains the same thing twice. I think thins works in your usecase. The list would also be maintained in sorted order.

提交回复
热议问题