{
  "schema_version": 2,
  "id": "develop/clients/lettuce/prob",
  "title": "Probabilistic data types",
  "url": "https://redis.io/docs/latest/develop/clients/lettuce/prob/",
  "summary": "Learn how to use approximate calculations with Redis.",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-10T14:04:50+01:00",
  "page_type": "content",
  "content_hash": "6832ae6eb54eb65dd7cb2d5e702753fa45ed64a2ea09671dfbf5db30b340c59c",
  "sections": [
    {
      "id": "set-operations",
      "title": "Set operations",
      "role": "content",
      "text": "Redis supports the following approximate set operations:\n\n-   [Membership](#set-membership): The\n    [Bloom filter](https://redis.io/docs/latest/develop/data-types/probabilistic/bloom-filter) and\n    [Cuckoo filter](https://redis.io/docs/latest/develop/data-types/probabilistic/cuckoo-filter)\n    data types let you track whether or not a given item is a member of a set.\n-   [Cardinality](#set-cardinality): The\n    [HyperLogLog](https://redis.io/docs/latest/develop/data-types/probabilistic/hyperloglogs)\n    data type gives you an approximate value for the number of items in a set, also\n    known as the *cardinality* of the set.\n\nThe sections below describe these operations in more detail."
    },
    {
      "id": "set-membership",
      "title": "Set membership",
      "role": "content",
      "text": "[Bloom filter](https://redis.io/docs/latest/develop/data-types/probabilistic/bloom-filter) and\n[Cuckoo filter](https://redis.io/docs/latest/develop/data-types/probabilistic/cuckoo-filter)\nobjects provide a set membership operation that lets you track whether or not a\nparticular item has been added to a set. These two types provide different\ntrade-offs for memory usage and speed, so you can select the best one for your\nuse case. Note that for both types, there is an asymmetry between presence and\nabsence of items in the set. If an item is reported as absent, then it is definitely\nabsent, but if it is reported as present, then there is a small chance it may really be\nabsent.\n\nInstead of storing strings directly, like a [set](https://redis.io/docs/latest/develop/data-types/sets),\na Bloom filter records the presence or absence of the\n[hash value](https://en.wikipedia.org/wiki/Hash_function) of a string.\nThis gives a very compact representation of the\nset's membership with a fixed memory size, regardless of how many items you\nadd. The following example adds some names to a Bloom filter representing\na list of users and checks for the presence or absence of users in the list.\n\nFoundational: Use Bloom filters for memory-efficient set membership testing with false positive possibility\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nA Cuckoo filter has similar features to a Bloom filter, but also supports\na deletion operation to remove hashes from a set, as shown in the example\nbelow.\n\nFoundational: Use Cuckoo filters for set membership testing with deletion support and faster lookups than Bloom filters\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nWhich of these two data types you choose depends on your use case.\nBloom filters are generally faster than Cuckoo filters when adding new items,\nand also have better memory usage. Cuckoo filters are generally faster\nat checking membership and also support the delete operation. See the\n[Bloom filter](https://redis.io/docs/latest/develop/data-types/probabilistic/bloom-filter) and\n[Cuckoo filter](https://redis.io/docs/latest/develop/data-types/probabilistic/cuckoo-filter)\nreference pages for more information and comparison between the two types."
    },
    {
      "id": "set-cardinality",
      "title": "Set cardinality",
      "role": "content",
      "text": "A [HyperLogLog](https://redis.io/docs/latest/develop/data-types/probabilistic/hyperloglogs)\nobject calculates the cardinality of a set. As you add\nitems, the HyperLogLog tracks the number of distinct set members but\ndoesn't let you retrieve them or query which items have been added.\nYou can also merge two or more HyperLogLogs to find the cardinality of the\n[union](https://en.wikipedia.org/wiki/Union_(set_theory)) of the sets they\nrepresent.\n\nFoundational: Estimate set cardinality with HyperLogLog for memory-efficient counting of distinct items\n\n**Difficulty:** Beginner\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nThe main benefit that HyperLogLogs offer is their very low\nmemory usage. They can count up to 2^64 items with less than\n1% standard error using a maximum 12KB of memory. This makes\nthem very useful for counting things like the total of distinct\nIP addresses that access a website or the total of distinct\nbank card numbers that make purchases within a day."
    },
    {
      "id": "statistics",
      "title": "Statistics",
      "role": "content",
      "text": "Redis supports several approximate statistical calculations\non numeric data sets:\n\n-   [Frequency](#frequency): The\n    [Count-min sketch](https://redis.io/docs/latest/develop/data-types/probabilistic/count-min-sketch)\n    data type lets you find the approximate frequency of a labeled item in a data stream.\n-   [Quantiles](#quantiles): The\n    [t-digest](https://redis.io/docs/latest/develop/data-types/probabilistic/t-digest)\n    data type estimates the quantile of a query value in a data stream.\n-   [Ranking](#ranking): The\n    [Top-K](https://redis.io/docs/latest/develop/data-types/probabilistic/top-k) data type\n    estimates the ranking of labeled items by frequency in a data stream.\n\nThe sections below describe these operations in more detail."
    },
    {
      "id": "frequency",
      "title": "Frequency",
      "role": "content",
      "text": "A [Count-min sketch](https://redis.io/docs/latest/develop/data-types/probabilistic/count-min-sketch)\n(CMS) object keeps count of a set of related items represented by\nstring labels. The count is approximate, but you can specify\nhow close you want to keep the count to the true value (as a fraction)\nand the acceptable probability of failing to keep it in this\ndesired range. For example, you can request that the count should\nstay within 0.1% of the true value and have a 0.05% probability\nof going outside this limit. The example below shows how to create\na Count-min sketch object, add data to it, and then query it.\n\nFoundational: Track approximate item frequencies with Count-min sketch for memory-efficient statistics on data streams\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nThe advantage of using a CMS over keeping an exact count with a\n[sorted set](https://redis.io/docs/latest/develop/data-types/sorted-sets)\nis that that a CMS has very low and fixed memory usage, even for\nlarge numbers of items. Use CMS objects to keep daily counts of\nitems sold, accesses to individual web pages on your site, and\nother similar statistics."
    },
    {
      "id": "quantiles",
      "title": "Quantiles",
      "role": "content",
      "text": "A [quantile](https://en.wikipedia.org/wiki/Quantile) is the value\nbelow which a certain fraction of samples lie. For example, with\na set of measurements of people's heights, the quantile of 0.75 is\nthe value of height below which 75% of all people's heights lie.\n[Percentiles](https://en.wikipedia.org/wiki/Percentile) are equivalent\nto quantiles, except that the fraction is expressed as a percentage.\n\nA [t-digest](https://redis.io/docs/latest/develop/data-types/probabilistic/t-digest)\nobject can estimate quantiles from a set of values added to it\nwithout having to store each value in the set explicitly. This can\nsave a lot of memory when you have a large number of samples.\n\nThe example below shows how to add data samples to a t-digest\nobject and obtain some basic statistics, such as the minimum and\nmaximum values, the quantile of 0.75, and the\n[cumulative distribution function](https://en.wikipedia.org/wiki/Cumulative_distribution_function)\n(CDF), which is effectively the inverse of the quantile function. It also\nshows how to merge two or more t-digest objects to query the combined\ndata set.\n\nFoundational: Estimate quantiles and percentiles with t-digest for memory-efficient statistical analysis of large datasets\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n\n\nA t-digest object also supports several other related commands, such\nas querying by rank. See the\n[t-digest](https://redis.io/docs/latest/develop/data-types/probabilistic/t-digest)\nreference for more information."
    },
    {
      "id": "ranking",
      "title": "Ranking",
      "role": "content",
      "text": "A [Top-K](https://redis.io/docs/latest/develop/data-types/probabilistic/top-k)\nobject estimates the rankings of different labeled items in a data\nstream according to frequency. For example, you could use this to\ntrack the top ten most frequently-accessed pages on a website, or the\ntop five most popular items sold.\n\nThe example below adds several different items to a Top-K object\nthat tracks the top three items (this is the second parameter to\nthe `topKReserve()` method). It also shows how to list the\ntop *k* items and query whether or not a given item is in the\nlist.\n\nFoundational: Track top K most frequent items in a data stream with Top-K for efficient ranking without storing all items\n\n**Difficulty:** Intermediate\n\n**Available in:** Java (Asynchronous - Lettuce), Java (Reactive - Lettuce)\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]"
    }
  ],
  "examples": [
    {
      "id": "set-membership-ex0",
      "language": "java",
      "code": "CompletableFuture<Void> bloomExample = asyncCommands\n                    .bfMAdd(\"recorded_users\", \"andy\", \"cameron\", \"david\", \"michelle\")\n                    .thenCompose(res1 -> {\n                        System.out.println(res1);\n                        // >>> [true, true, true, true]\n                        return asyncCommands.bfExists(\"recorded_users\", \"cameron\");\n                    })\n                    .thenCompose(res2 -> {\n                        System.out.println(res2);\n                        // >>> true\n                        return asyncCommands.bfExists(\"recorded_users\", \"kaitlyn\");\n                    })\n                    .thenAccept(res3 -> {\n                        System.out.println(res3);\n                        // >>> false\n                    })\n                    .toCompletableFuture();\n\n            bloomExample.join();",
      "section_id": "set-membership"
    },
    {
      "id": "set-membership-ex1",
      "language": "java",
      "code": "List<Boolean> res1 = reactiveCommands\n                    .bfMAdd(\"recorded_users\", \"andy\", \"cameron\", \"david\", \"michelle\")\n                    .map(Value::getValue)\n                    .collectList()\n                    .block();\n            System.out.println(res1);\n            // >>> [true, true, true, true]\n\n            Boolean res2 = reactiveCommands.bfExists(\"recorded_users\", \"cameron\").block();\n            System.out.println(res2);\n            // >>> true\n\n            Boolean res3 = reactiveCommands.bfExists(\"recorded_users\", \"kaitlyn\").block();\n            System.out.println(res3);\n            // >>> false",
      "section_id": "set-membership"
    },
    {
      "id": "set-membership-ex2",
      "language": "java",
      "code": "CompletableFuture<Void> cuckooExample = asyncCommands\n                    .cfAdd(\"other_users\", \"paolo\")\n                    .thenCompose(res4 -> {\n                        System.out.println(res4);\n                        // >>> true\n                        return asyncCommands.cfAdd(\"other_users\", \"kaitlyn\");\n                    })\n                    .thenCompose(res5 -> {\n                        System.out.println(res5);\n                        // >>> true\n                        return asyncCommands.cfAdd(\"other_users\", \"rachel\");\n                    })\n                    .thenCompose(res6 -> {\n                        System.out.println(res6);\n                        // >>> true\n                        return asyncCommands.cfMExists(\"other_users\", \"paolo\", \"rachel\", \"andy\");\n                    })\n                    .thenCompose(res7 -> {\n                        System.out.println(res7);\n                        // >>> [true, true, false]\n                        return asyncCommands.cfDel(\"other_users\", \"paolo\");\n                    })\n                    .thenCompose(res8 -> {\n                        System.out.println(res8);\n                        // >>> true\n                        return asyncCommands.cfExists(\"other_users\", \"paolo\");\n                    })\n                    .thenAccept(res9 -> {\n                        System.out.println(res9);\n                        // >>> false\n                    })\n                    .toCompletableFuture();\n\n            cuckooExample.join();",
      "section_id": "set-membership"
    },
    {
      "id": "set-membership-ex3",
      "language": "java",
      "code": "Boolean res4 = reactiveCommands.cfAdd(\"other_users\", \"paolo\").block();\n            System.out.println(res4);\n            // >>> true\n\n            Boolean res5 = reactiveCommands.cfAdd(\"other_users\", \"kaitlyn\").block();\n            System.out.println(res5);\n            // >>> true\n\n            Boolean res6 = reactiveCommands.cfAdd(\"other_users\", \"rachel\").block();\n            System.out.println(res6);\n            // >>> true\n\n            List<Boolean> res7 = reactiveCommands\n                    .cfMExists(\"other_users\", \"paolo\", \"rachel\", \"andy\")\n                    .collectList()\n                    .block();\n            System.out.println(res7);\n            // >>> [true, true, false]\n\n            Boolean res8 = reactiveCommands.cfDel(\"other_users\", \"paolo\").block();\n            System.out.println(res8);\n            // >>> true\n\n            Boolean res9 = reactiveCommands.cfExists(\"other_users\", \"paolo\").block();\n            System.out.println(res9);\n            // >>> false",
      "section_id": "set-membership"
    },
    {
      "id": "set-cardinality-ex0",
      "language": "java",
      "code": "CompletableFuture<Void> hllExample = asyncCommands\n                    .pfadd(\"group:1\", \"andy\", \"cameron\", \"david\")\n                    .thenCompose(res10 -> {\n                        System.out.println(res10);\n                        // >>> 1\n                        return asyncCommands.pfcount(\"group:1\");\n                    })\n                    .thenCompose(res11 -> {\n                        System.out.println(res11);\n                        // >>> 3\n                        return asyncCommands.pfadd(\"group:2\", \"kaitlyn\", \"michelle\", \"paolo\", \"rachel\");\n                    })\n                    .thenCompose(res12 -> {\n                        System.out.println(res12);\n                        // >>> 1\n                        return asyncCommands.pfcount(\"group:2\");\n                    })\n                    .thenCompose(res13 -> {\n                        System.out.println(res13);\n                        // >>> 4\n                        return asyncCommands.pfmerge(\"both_groups\", \"group:1\", \"group:2\");\n                    })\n                    .thenCompose(res14 -> {\n                        System.out.println(res14);\n                        // >>> OK\n                        return asyncCommands.pfcount(\"both_groups\");\n                    })\n                    .thenAccept(res15 -> {\n                        System.out.println(res15);\n                        // >>> 7\n                    })\n                    .toCompletableFuture();\n\n            hllExample.join();",
      "section_id": "set-cardinality"
    },
    {
      "id": "set-cardinality-ex1",
      "language": "java",
      "code": "Long res10 = reactiveCommands.pfadd(\"group:1\", \"andy\", \"cameron\", \"david\").block();\n            System.out.println(res10);\n            // >>> 1\n\n            Long res11 = reactiveCommands.pfcount(\"group:1\").block();\n            System.out.println(res11);\n            // >>> 3\n\n            Long res12 = reactiveCommands.pfadd(\"group:2\", \"kaitlyn\", \"michelle\", \"paolo\", \"rachel\").block();\n            System.out.println(res12);\n            // >>> 1\n\n            Long res13 = reactiveCommands.pfcount(\"group:2\").block();\n            System.out.println(res13);\n            // >>> 4\n\n            String res14 = reactiveCommands.pfmerge(\"both_groups\", \"group:1\", \"group:2\").block();\n            System.out.println(res14);\n            // >>> OK\n\n            Long res15 = reactiveCommands.pfcount(\"both_groups\").block();\n            System.out.println(res15);\n            // >>> 7",
      "section_id": "set-cardinality"
    },
    {
      "id": "frequency-ex0",
      "language": "java",
      "code": "CompletableFuture<Void> cmsExample = asyncCommands\n                    // Specify that you want to keep the counts within 0.01\n                    // (1%) of the true value with a 0.005 (0.5%) chance\n                    // of going outside this limit.\n                    .cmsInitByProb(\"items_sold\", 0.01, 0.005)\n                    .thenCompose(res16 -> {\n                        System.out.println(res16);\n                        // >>> OK\n                        return asyncCommands.cmsIncrBy(\"items_sold\",\n                                IncrementPair.of(\"bread\", 300L),\n                                IncrementPair.of(\"tea\", 200L),\n                                IncrementPair.of(\"coffee\", 200L),\n                                IncrementPair.of(\"beer\", 100L));\n                    })\n                    .thenCompose(res17 -> {\n                        List<Long> sorted17 = new ArrayList<>(res17);\n                        sorted17.sort(null);\n                        System.out.println(sorted17);\n                        // >>> [100, 200, 200, 300]\n                        return asyncCommands.cmsIncrBy(\"items_sold\",\n                                IncrementPair.of(\"bread\", 100L),\n                                IncrementPair.of(\"coffee\", 150L));\n                    })\n                    .thenCompose(res18 -> {\n                        List<Long> sorted18 = new ArrayList<>(res18);\n                        sorted18.sort(null);\n                        System.out.println(sorted18);\n                        // >>> [350, 400]\n                        return asyncCommands.cmsQuery(\"items_sold\", \"bread\", \"tea\", \"coffee\", \"beer\");\n                    })\n                    .thenAccept(res19 -> {\n                        List<Long> sorted19 = new ArrayList<>(res19);\n                        sorted19.sort(null);\n                        System.out.println(sorted19);\n                        // >>> [100, 200, 350, 400]\n                    })\n                    .toCompletableFuture();\n\n            cmsExample.join();",
      "section_id": "frequency"
    },
    {
      "id": "frequency-ex1",
      "language": "java",
      "code": "// Specify that you want to keep the counts within 0.01\n            // (1%) of the true value with a 0.005 (0.5%) chance\n            // of going outside this limit.\n            String res16 = reactiveCommands.cmsInitByProb(\"items_sold\", 0.01, 0.005).block();\n            System.out.println(res16);\n            // >>> OK\n\n            List<Long> res17 = new ArrayList<>(reactiveCommands\n                    .cmsIncrBy(\"items_sold\",\n                            IncrementPair.of(\"bread\", 300L),\n                            IncrementPair.of(\"tea\", 200L),\n                            IncrementPair.of(\"coffee\", 200L),\n                            IncrementPair.of(\"beer\", 100L))\n                    .collectList()\n                    .block());\n            res17.sort(null);\n            System.out.println(res17);\n            // >>> [100, 200, 200, 300]\n\n            List<Long> res18 = new ArrayList<>(reactiveCommands\n                    .cmsIncrBy(\"items_sold\",\n                            IncrementPair.of(\"bread\", 100L),\n                            IncrementPair.of(\"coffee\", 150L))\n                    .collectList()\n                    .block());\n            res18.sort(null);\n            System.out.println(res18);\n            // >>> [350, 400]\n\n            List<Long> res19 = new ArrayList<>(reactiveCommands\n                    .cmsQuery(\"items_sold\", \"bread\", \"tea\", \"coffee\", \"beer\")\n                    .collectList()\n                    .block());\n            res19.sort(null);\n            System.out.println(res19);\n            // >>> [100, 200, 350, 400]",
      "section_id": "frequency"
    },
    {
      "id": "quantiles-ex0",
      "language": "java",
      "code": "CompletableFuture<Void> tdigestExample = asyncCommands\n                    .tdigestCreate(\"male_heights\")\n                    .thenCompose(res20 -> {\n                        System.out.println(res20);\n                        // >>> OK\n                        return asyncCommands.tdigestAdd(\"male_heights\",\n                                175.5, 181, 160.8, 152, 177, 196, 164);\n                    })\n                    .thenCompose(res21 -> {\n                        System.out.println(res21);\n                        // >>> OK\n                        return asyncCommands.tdigestMin(\"male_heights\");\n                    })\n                    .thenCompose(res22 -> {\n                        System.out.println(res22);\n                        // >>> 152.0\n                        return asyncCommands.tdigestMax(\"male_heights\");\n                    })\n                    .thenCompose(res23 -> {\n                        System.out.println(res23);\n                        // >>> 196.0\n                        return asyncCommands.tdigestQuantile(\"male_heights\", 0.75);\n                    })\n                    .thenCompose(res24 -> {\n                        System.out.println(res24);\n                        // >>> [181.0]\n                        // Note that the CDF value for 181 is not exactly 0.75.\n                        // Both values are estimates.\n                        return asyncCommands.tdigestCDF(\"male_heights\", 181);\n                    })\n                    .thenCompose(res25 -> {\n                        System.out.println(res25);\n                        // >>> [0.7857142857142857]\n                        return asyncCommands.tdigestCreate(\"female_heights\");\n                    })\n                    .thenCompose(res26 -> {\n                        System.out.println(res26);\n                        // >>> OK\n                        return asyncCommands.tdigestAdd(\"female_heights\",\n                                155.5, 161, 168.5, 170, 157.5, 163, 171);\n                    })\n                    .thenCompose(res27 -> {\n                        System.out.println(res27);\n                        // >>> OK\n                        return asyncCommands.tdigestQuantile(\"female_heights\", 0.75);\n                    })\n                    .thenCompose(res28 -> {\n                        System.out.println(res28);\n                        // >>> [170.0]\n                        return asyncCommands.tdigestMerge(\"all_heights\", \"male_heights\", \"female_heights\");\n                    })\n                    .thenCompose(res29 -> {\n                        System.out.println(res29);\n                        // >>> OK\n                        return asyncCommands.tdigestQuantile(\"all_heights\", 0.75);\n                    })\n                    .thenAccept(res30 -> {\n                        System.out.println(res30);\n                        // >>> [175.5]\n                    })\n                    .toCompletableFuture();\n\n            tdigestExample.join();",
      "section_id": "quantiles"
    },
    {
      "id": "quantiles-ex1",
      "language": "java",
      "code": "String res20 = reactiveCommands.tdigestCreate(\"male_heights\").block();\n            System.out.println(res20);\n            // >>> OK\n\n            String res21 = reactiveCommands.tdigestAdd(\"male_heights\",\n                    175.5, 181, 160.8, 152, 177, 196, 164).block();\n            System.out.println(res21);\n            // >>> OK\n\n            Double res22 = reactiveCommands.tdigestMin(\"male_heights\").block();\n            System.out.println(res22);\n            // >>> 152.0\n\n            Double res23 = reactiveCommands.tdigestMax(\"male_heights\").block();\n            System.out.println(res23);\n            // >>> 196.0\n\n            List<Double> res24 = reactiveCommands.tdigestQuantile(\"male_heights\", 0.75)\n                    .collectList().block();\n            System.out.println(res24);\n            // >>> [181.0]\n\n            // Note that the CDF value for 181 is not exactly 0.75.\n            // Both values are estimates.\n            List<Double> res25 = reactiveCommands.tdigestCDF(\"male_heights\", 181)\n                    .collectList().block();\n            System.out.println(res25);\n            // >>> [0.7857142857142857]\n\n            String res26 = reactiveCommands.tdigestCreate(\"female_heights\").block();\n            System.out.println(res26);\n            // >>> OK\n\n            String res27 = reactiveCommands.tdigestAdd(\"female_heights\",\n                    155.5, 161, 168.5, 170, 157.5, 163, 171).block();\n            System.out.println(res27);\n            // >>> OK\n\n            List<Double> res28 = reactiveCommands.tdigestQuantile(\"female_heights\", 0.75)\n                    .collectList().block();\n            System.out.println(res28);\n            // >>> [170.0]\n\n            String res29 = reactiveCommands.tdigestMerge(\"all_heights\", \"male_heights\", \"female_heights\").block();\n            System.out.println(res29);\n            // >>> OK\n\n            List<Double> res30 = reactiveCommands.tdigestQuantile(\"all_heights\", 0.75)\n                    .collectList().block();\n            System.out.println(res30);\n            // >>> [175.5]",
      "section_id": "quantiles"
    },
    {
      "id": "ranking-ex0",
      "language": "java",
      "code": "CompletableFuture<Void> topkExample = asyncCommands\n                    .topKReserve(\"top_3_songs\", 3L,\n                            TopKReserveArgs.Builder.width(2000L).depth(7L).decay(0.925))\n                    .thenCompose(res31 -> {\n                        System.out.println(res31);\n                        // >>> OK\n                        return asyncCommands.topKIncrBy(\"top_3_songs\",\n                                IncrementPair.of(\"Starfish Trooper\", 3000L),\n                                IncrementPair.of(\"Only one more time\", 1850L),\n                                IncrementPair.of(\"Rock me, Handel\", 1325L),\n                                IncrementPair.of(\"How will anyone know?\", 3890L),\n                                IncrementPair.of(\"Average lover\", 4098L),\n                                IncrementPair.of(\"Road to everywhere\", 770L));\n                    })\n                    .thenCompose(res32 -> {\n                        System.out.println(res32);\n                        // >>> [null, null, null, Rock me, Handel, Only one more time, null]\n                        return asyncCommands.topKList(\"top_3_songs\");\n                    })\n                    .thenCompose(res33 -> {\n                        System.out.println(res33);\n                        // >>> [Average lover, How will anyone know?, Starfish Trooper]\n                        return asyncCommands.topKQuery(\"top_3_songs\", \"Starfish Trooper\", \"Road to everywhere\");\n                    })\n                    .thenAccept(res34 -> {\n                        System.out.println(res34);\n                        // >>> [true, false]\n                    })\n                    .toCompletableFuture();\n\n            topkExample.join();",
      "section_id": "ranking"
    },
    {
      "id": "ranking-ex1",
      "language": "java",
      "code": "String res31 = reactiveCommands.topKReserve(\"top_3_songs\", 3L,\n                    TopKReserveArgs.Builder.width(2000L).depth(7L).decay(0.925)).block();\n            System.out.println(res31);\n            // >>> OK\n\n            List<Value<String>> res32 = reactiveCommands\n                    .topKIncrBy(\"top_3_songs\",\n                            IncrementPair.of(\"Starfish Trooper\", 3000L),\n                            IncrementPair.of(\"Only one more time\", 1850L),\n                            IncrementPair.of(\"Rock me, Handel\", 1325L),\n                            IncrementPair.of(\"How will anyone know?\", 3890L),\n                            IncrementPair.of(\"Average lover\", 4098L),\n                            IncrementPair.of(\"Road to everywhere\", 770L))\n                    .collectList()\n                    .block();\n            System.out.println(res32);\n            // >>> [Value.empty, Value.empty, Value.empty, Value[Rock me, Handel], Value[Only one more time], Value.empty]\n\n            List<String> res33 = reactiveCommands.topKList(\"top_3_songs\").collectList().block();\n            System.out.println(res33);\n            // >>> [Average lover, How will anyone know?, Starfish Trooper]\n\n            List<Boolean> res34 = reactiveCommands\n                    .topKQuery(\"top_3_songs\", \"Starfish Trooper\", \"Road to everywhere\")\n                    .collectList()\n                    .block();\n            System.out.println(res34);\n            // >>> [true, false]",
      "section_id": "ranking"
    }
  ]
}
