No, there is no simple trick for this.
Redis is a store, not a database management system. It does not support query language. If you need some data to retrieve, you need to provide access paths in advance and create the data structure accordingly.
For example, in your example, you could support zset when adding / removing elements from sets of interest to you. In this zset, the value will be the set key, and the estimate will be the number of the set.
Retrieving zset content by rank will give you a set sorted by power.
If you haven't planned this access path and still need data, you will have no choice but to use a programming language. If you cannot install any Redis driver, you can work with the Redis dump file (which should be generated by the BGSAVE command), load this file into another block and use the following package from Sripathi Krishnan to analyze it and calculate the statistics that you required.
https://github.com/sripathikrishnan/redis-rdb-tools
source share