Azure 表存储实体中的数组(非字节)
我希望将数组存储在 Azure 表实体中。目前,原生支持的唯一数组类型是字节数组,长度限制为 64k。大小足够了,但我想在实体中存储长整型、双精度型和时间戳的数组。
显然,我可以自己将多个字节转换为请求的类型,但我想知道是否有任何最佳实践可以实现这一点。
澄清一下,这些是与单个键关联的固定长度数组(例如 1000 个单元)。
I'm looking to store arrays in Azure Table entities. At present, the only type of array supported natively is byte-array, limited to 64k length. The size is enough, but I'd like to store arrays of longs, doubles and timestamps in an entity.
I can obviously cast multiple bytes to the requested type myself, but I was wondering if there's any best-practice to achieve that.
To clarify, these are fixed length arrays (e.g. 1000 cells) associated with a single key.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我编写了一个 Azure 表存储客户端,名为 Lucifure Stash,它支持数组、枚举、大数据、序列化、公共和私有属性和字段等。
您可以在 https://github.com/hocho/LucifureStash 获取它
I have written a Azure table storage client, called Lucifure Stash, which supports arrays, enums, large data, serialization, public and private properties and fields and more.
You can get it at https://github.com/hocho/LucifureStash
除了您已经提到的方法之外,我一直在尝试想出一种好方法来做到这一点,但我不知所措。我能想到的最简单的解决方案是获取数组,对其进行二进制序列化并存储在二进制数组属性中。
我提出但被驳回的其他选项:
I've been trying to think of a nice way to do this other than the method you've already mentioned, and I'm at a loss. The simplest solution I can come up with is to take the array, binary serialize it and store in a binary array property.
Other options I've come up with but dismissed:
如果您只需要存储一个键值集合,那么您还可以查看 Azure BLOB。它们可以相当有效地存储每个 blob 最多 25M 时间值点的数组(在数据集中进行随机访问)。
If you have just a key-value collection to store, then you can also check out Azure BLOBs. They can rather efficiently store arrays of up to 25M time-value points per single blob (with a random access within the dataset).
如果您选择将对象存储在 Blob 存储中,并且需要多个“密钥”来获取它,则只需创建一个或两个或 n 个 Azure 表,在其中存储要查找的密钥以及对确切 Blob 的引用物品。
If you choose to store your object in blob storage and need more than one "key" to get it, you can just create an azure table or two or n where you store the key you want to look up and the reference to the exact blob item.
为什么不将值存储为 csv 字符串?
Why don't you store the values as csv strings?
您可以使用 .NET JavaScript 序列化器将数组序列化为 JSON 字符串:
http://msdn.microsoft.com/en -us/library/system.web.script.serialization.javascriptserializer.aspx
这个类有一个“MaxJsonLength”属性,您可以使用它来确保数组在序列化时不超过 64K。您可以使用相同的类来反序列化存储的对象。
You could serialize your array as a JSON string using the .NET JavaScript serializer:
http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx
This class has a "MaxJsonLength" property you could use to ensure your arrays didn't exceed 64K when you were serializing them. And you can use the same class to deserialize your stored objects.