Count number of records in lmdb databse with pytho

2019-05-24 15: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?

标签: python lmdb
3条回答
Animai°情兽
2楼-- · 2019-05-24 16:13

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}
查看更多
干净又极端
3楼-- · 2019-05-24 16:31

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.

查看更多
淡お忘
4楼-- · 2019-05-24 16:35

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.

查看更多
登录 后发表回答