在带有Python的Berkeley DB中使用整数键(使用bsddb3) [英] Use integer keys in Berkeley DB with python (using bsddb3)
问题描述
我想将BDB用作时间序列数据存储,并计划将自纪元以来的微秒用作键值.我正在使用BTREE作为数据存储类型.
I want to use BDB as a time-series data store, and planning to use the microseconds since epoch as the key values. I am using BTREE as the data store type.
但是,当我尝试存储整数键时,bsddb3给出错误消息TypeError: Integer keys only allowed for Recno and Queue DB's
.
However, when I try to store integer keys, bsddb3 gives an error saying TypeError: Integer keys only allowed for Recno and Queue DB's
.
最佳解决方法是什么?我可以将它们存储为字符串,但这可能会使它不必要地变慢.
What is the best workaround? I can store them as strings, but that probably will make it unnecessarily slower.
鉴于BDB本身可以处理任何类型的数据,为什么会有限制?我可以排序bsddb3实现吗?有没有人用过其他方法?
Given BDB itself can handle any kind of data, why is there a restriction? can I sorta hack the bsddb3 implementation? has anyone used anyother methods?
推荐答案
嗯,没有解决方法.但是您可以使用两种方法
Well, there's no workaround. But you can use two approaches
-
使用
str
或repr
将整数存储为字符串.如果整数很大,甚至可以使用字符串格式
Store the integers as string using
str
orrepr
. If the ints are big, you can even use string formatting
使用cPickle/pickle模块存储和检索数据.如果您具有基本类型以外的数据类型,则这是一种好方法.对于int
和float
的基础知识,这实际上比仅存储字符串慢并且占用更多空间
use cPickle/pickle module to store and retrieve data. This is a good way if you have data types other than basic types. For basics int
s and float
s this actually is slower and takes more space than just storing strings
这篇关于在带有Python的Berkeley DB中使用整数键(使用bsddb3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!