简体   繁体   English

在Cassandra 2+中存储简单的键值对

[英]Store simple key-value pairs in Cassandra 2+

currently we're using HBase to store our data. 当前,我们正在使用HBase来存储数据。 Therefore we created an abstract class that holds a Map, and this map is then stored via the Java API. 因此,我们创建了一个包含Map的抽象类,然后通过Java API存储此Map。 a sample class would be 一个示例类将是

class User extends AHBase {
  public static String columnName = "nam".getBytes();
  //...
  public void setName(String name) {
    values.put(columnName, name.getBytes());
  }
  public String getName() {
    return new String(values.get(columnName));
  }
  public byte[] getColumnFamily() {...}
  public byte[] getTable() {...}
}

and a store is as simple as (simplified) 商店就像(简体)一样简单

public void store(AHbase a) {
  List<Put> puts = new ArrayList<>();
  for (Entry<byte[], byte[] item : a.getValues().entrySet()) {
    Put p = new Put(a.getColumnFamily, item.getKey(), item.getValue());
    puts.add(p);
  }
  //...
}

we are now evaluating Cassandra, as it's said to be also a key-value store and it should be easy to just switch and do some basic evaluation (at least we thought so). 我们现在正在评估Cassandra,因为据说它也是一个键值存储,只需切换并进行一些基本评估就应该很容易(至少我们这么认为)。

But now when checking out the latest version of Cassandra (2.1.2) it's kind of not what we expected. 但是现在,当检查最新版本的Cassandra(2.1.2)时,这不是我们期望的。

Is there still a simple way to store key-value pairs (for a ColumnFamily) with basic put operations or similar? 是否还有一种简单的方法可以通过基本的put操作或类似操作存储键值对(对于ColumnFamily)? I want to avoid having to define the column names in advance. 我想避免必须预先定义列名称。

Cassandra has definitely deviated away from the thrift model of storing data but you can still get a similar partition layout in cql with something like: Cassandra确实偏离了存储数据的节俭模型,但是您仍然可以在cql中获得类似以下内容的分区布局:

partition blob, key blob , value blob, PRIMARY KEY partition,key

or 要么

key blob, value blob, PRIMARY KEY key

Depending on if you want to have multiple keys in a partition or not. 取决于是否要在分区中具有多个键。

Thrift is still available but is definitely one foot out the door at the moment. 节俭仍然可以使用,但目前绝对是一英尺之遥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM