Berkeley DB:如何从 QUEUE 获取特定的 KEY

发布于 2025-01-08 03:17:27 字数 611 浏览 5 评论 0原文

我正在将一些固定长度的记录写入 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘虞初梦 2025-01-15 03:17:27

如果需要随机访问,请尝试除 DB_QUEUE 之外的其他数据库格式。

Try some other database format than DB_QUEUE if you need random access.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文