我想通过python获取Aerospike集合中的记录总数。
我猜,它是在
show sets
-
aql> show sets
+-----------+------------------+----------------+-------------------+----------------+---------------------+--------------------------------------------+------------+
| n_objects | disable-eviction | set-enable-xdr | stop-writes-count | n-bytes-memory | ns_name | set_name | set-delete |
+
| 179 | "true" | "use-default" | 0 | 0 | "namespace" | "setName" | "false" |
从我读到的内容来看,似乎只有通过Lua脚本才能实现-
https://discuss.aerospike.com/t/fastest-way-to-count-records-returned-by-a-query/2379/4
有人能证实吗?
但是,我可以通过使用计数器变量通过迭代
select()
和上面的数字相符-
client = aerospike.client(config).connect()
scan = client.scan('namespace', 'set')
scan.select('PK','expiresIn','clientId','scopes','roles')
scan.foreach(process_result)
print "Total aeroCount"
print aeroCount
def process_result((key, metadata, record)):
global aeroCount
aeroCount=aeroCount+1
更新
我试过运行命令
asinfo -v sets
首先在命令行上。它也给了我物品的数量,像这样-
ns=namespace:set=setName:objects=29949:
.
不确定如何准确地从中获取对象对集的计数。这个命令是否符合python函数的命令?我试过了
client = aerospike.client(config).connect()
response = client.info_all("asinfo -v sets")
我犯了一个错误-
File "Sandeepan-oauth_token_cache_complete_sanity_cp.py", line 89, in <module>
response = client.info_all("asinfo -v sets")
AttributeError: 'aerospike.Client' object has no attribute 'info_all'