Getting length from a stream efficiently

+1 vote

I need to get the length from a stream at some key. For this I simply do: len(api.liststreamkeyitems('myStream', 'myKey'). However, this takes some time if the returned list is huge. Is there a way to do this efficiently? Note that I just need the length list, not the elements itself.

asked Aug 30, 2018 by TinfoilHat

1 Answer

+1 vote
Best answer

api.liststreamkeys('myStream') does what I want. It simply returns a list of dictionaries that has fields confirmations, items, key. Items list how many items are there in the corresponding key.

answered Aug 30, 2018 by TinfoilHat
selected Aug 31, 2018 by TinfoilHat
You can do even better than that. Pass in the specific key you're interested in for the second parameter for liststreamkeys, and you'll get the information about that key only.