Berkeley DB:如何从 QUEUE 获取特定的 KEY
我正在将一些固定长度的记录写入 Berkeley DB 中的队列,并在每次 PUT 后返回记录号。因此,例如,如果我将 4 条消息放入队列中,我将返回 1、2、3、4。
现在我想根据它的 KEY 从队列中检索一条消息......
所以,如果我尝试:
db_recno_t keyval;
DBT key, data;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
keyval = 2;
key.data = &keyval;
key.ulen = sizeof(keyval);
ret = q->get(q, NULL, &key, &data, DB_CONSUME);
printf("Key peek = %i\n", keyval);
printf("Data peek = %s\n", data.data);
我会不断得到返回队列中的第一个记录,而不是我用键指定的记录(在本例中为“2”)
我知道队列上的键是 1,2,3,4 所以我想知道我在这里做了什么愚蠢的事情?
感谢您的帮助,非常感谢;-)
林顿
I am writing some fixed length records to a QUEUE in Berkeley DB, and get back the record number agter each PUT. So for example if I put 4 messages on the queue I am getting back 1, 2, 3, 4.
NOw I would like to retrieve a message from the queue based on it's KEY....
So if I try:
db_recno_t keyval;
DBT key, data;
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
keyval = 2;
key.data = &keyval;
key.ulen = sizeof(keyval);
ret = q->get(q, NULL, &key, &data, DB_CONSUME);
printf("Key peek = %i\n", keyval);
printf("Data peek = %s\n", data.data);
I keep getting back the first record in the queue, not the one I specify with the key (in this case "2")
I know the keys are 1,2,3,4 on the queue so I am wondering what stupid thing I am doing here?
Thanks for the help, much aprreciated ;-)
Lynton
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果需要随机访问,请尝试除 DB_QUEUE 之外的其他数据库格式。
Try some other database format than DB_QUEUE if you need random access.