Count number of records in lmdb databse with python

匿名 (未验证) 提交于 2019-12-03 09:05:37

问题:

I open a lmdb database using this code:

    lmdb_env = lmdb.open(source_path, readonly=True) 

How can I count the number of records in this database?

回答1:

I think it should be like this:

lmdb_env = lmdb.open(lmdb_file_name, readonly=True) print lmdb_env.stat() 

Then it prints the directory that Jaco pasted here.



回答2:

I found a simple solution using for loop. Here it is:

count = 0 for key, value in lmdb_env.cursor():         count = count + 1   

However, I think there should be a better way using pre-defined function.



回答3:

You can use event.stat(). It will return the following dictionary with entries detailing the number of records in this database:

{'branch_pages': 1040L, 'depth': 4L,  'entries': 3761848L,  'leaf_pages': 73658L,  'overflow_pages': 0L,  'psize': 4096L} 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!