在 cassandra 中存储对象
是否可以在 Cassandra 列族中存储对象和数据结构?
例如:
object Person
{
string name;
string email;
Address address;
}
正如您所看到的,Person 对象中包含 Address 对象。
我可以这样保存吗?
$ set Person['me']['name'] = 'foo';
$ set Person['me']['email'] = '[email protected]';
地址怎么样?怎么做呢?
我正在使用 C# 客户端。
Is it possible to store object and data structures within Cassandra column families?
For example:
object Person
{
string name;
string email;
Address address;
}
As you can see Person object has Address object within it.
Can I store it like this?
$ set Person['me']['name'] = 'foo';
$ set Person['me']['email'] = '[email protected]';
How about address? How to do it?
I'm using C# client.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里不要使用超级列;这里不需要它们,并且还有其他缺点,例如不允许在列上使用二级索引。
您应该为地址的每个字段创建一列(如果由于某种原因需要在不同时间编辑它们),或者只是序列化地址(例如,转换为 JSON)并将其放入一列中。 cassandra-cli 没有用于序列化和反序列化数据的工具,因为它实际上只是一个实用程序或探索性工具;您需要对普通客户端执行此操作。
Don't use super columns here; they aren't needed here and have other drawbacks, such as not allowing secondary indexes on columns.
You should either create one column for each field of the address (if you need to edit them at different times for some reason), or just serialize the address (to JSON, for example) and put it in one column. The cassandra-cli doesn't have tools for serializing and deserializing data as it's really just a utility or exploratory tool; you'll need to do this with a normal client.