{
  "schema_version": 2,
  "id": "commands/rpop",
  "title": "RPOP",
  "url": "https://redis.io/docs/latest/commands/rpop/",
  "summary": "Returns and removes the last elements of a list. Deletes the list if the last element was popped.",
  "since": "1.0.0",
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-07-08T12:05:04+02:00",
  "page_type": "content",
  "content_hash": "2f80546e2ff2aca2424221ccfdadd88639dce65d840fcc89ffc3ad1305b0393f",
  "sections": [
    {
      "id": "required-arguments",
      "title": "Required arguments",
      "role": "content",
      "text": "<details open><summary><code>key</code></summary>\n\nThe name of the key that holds the list.\n\n</details>"
    },
    {
      "id": "optional-arguments",
      "title": "Optional arguments",
      "role": "parameters",
      "text": "<details open><summary><code>count</code></summary>\n\nThe number of elements to pop. Without it, a single element is popped.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Remove and return the last element(s) from a list using RPOP (supports optional count parameter to pop multiple elements from tail)\n\n**Difficulty:** Beginner\n\n**Commands:** RPUSH, RPOP, LRANGE\n\n**Complexity:**\n- RPUSH: O(1)\n- RPOP: O(N)\n- LRANGE: O(S+N)\n\n**Available in:** Redis CLI, C#, Go, Java (Asynchronous - Lettuce), Java (Reactive - Lettuce), Java (Synchronous - Jedis), JavaScript (Node.js), JavaScript (Node.js), PHP, Python, Ruby, Rust (Asynchronous), Rust (Synchronous)\n\n##### Redis CLI\n\n[code example]\n\n##### C#\n\n[code example]\n\n##### Go\n\n[code example]\n\n##### Java (Asynchronous - Lettuce)\n\n[code example]\n\n##### Java (Reactive - Lettuce)\n\n[code example]\n\n##### Java (Synchronous - Jedis)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### JavaScript (Node.js)\n\n[code example]\n\n##### PHP\n\n[code example]\n\n##### Python\n\n[code example]\n\n##### Ruby\n\n[code example]\n\n##### Rust (Asynchronous)\n\n[code example]\n\n##### Rust (Synchronous)\n\n[code example]"
    },
    {
      "id": "redis-software-and-redis-cloud-compatibility",
      "title": "Redis Software and Redis Cloud compatibility",
      "role": "content",
      "text": "| Redis<br />Software | Redis<br />Cloud | <span style=\"min-width: 9em; display: table-cell\">Notes</span> |\n|:----------------------|:-----------------|:------|\n| <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> | <span title=\"Supported\">&#x2705; Standard</span><br /><span title=\"Supported\"><nobr>&#x2705; Active-Active</nobr></span> |  |"
    },
    {
      "id": "return-information",
      "title": "Return information",
      "role": "returns",
      "text": "**RESP2:**\n\nOne of the following:\n* [Nil reply](../../develop/reference/protocol-spec#bulk-strings): if the key does not exist.\n* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): when called without the _count_ argument, the value of the last element.\n* [Array reply](../../develop/reference/protocol-spec#arrays): when called with the _count_ argument, a list of popped elements.\n\n**RESP3:**\n\nOne of the following:\n* [Null reply](../../develop/reference/protocol-spec#nulls): if the key does not exist.\n* [Bulk string reply](../../develop/reference/protocol-spec#bulk-strings): when called without the _count_ argument, the value of the last element.\n* [Array reply](../../develop/reference/protocol-spec#arrays): when called with the _count_ argument, a list of popped elements."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "redis> RPUSH mylist \"one\" \"two\" \"three\" \"four\" \"five\"\n(integer) 5\nredis> RPOP mylist\n\"five\"\nredis> RPOP mylist 2\n1) \"four\"\n2) \"three\"\nredis> LRANGE mylist 0 -1\n1) \"one\"\n2) \"two\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "csharp",
      "code": "long rPopResult1 = db.ListRightPush(\"mylist\", [\"one\", \"two\", \"three\", \"four\", \"five\"]);\n        Console.WriteLine(rPopResult1); // >>> 5\n\n        RedisValue rPopResult2 = db.ListRightPop(\"mylist\");\n        Console.WriteLine(rPopResult2); // >>> five\n\n        RedisValue[] rPopResult3 = db.ListRightPop(\"mylist\", 2);\n        Console.WriteLine($\"[{string.Join(\", \", rPopResult3)}]\");\n        // >>> [four, three]\n\n        RedisValue[] rPopResult4 = db.ListRange(\"mylist\", 0, -1);\n        Console.WriteLine($\"[{string.Join(\", \", rPopResult4)}]\");\n        // >>> [one, two]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "go",
      "code": "rPushResult, err := rdb.RPush(ctx, \"mylist\",\n\t\t\"one\", \"two\", \"three\", \"four\", \"five\",\n\t).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(rPushResult) // >>> 5\n\n\trPopResult, err := rdb.RPop(ctx, \"mylist\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(rPopResult) // >>> five\n\n\trPopCountResult, err := rdb.RPopCount(ctx, \"mylist\", 2).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(rPopCountResult) // >>> [four three]\n\n\tlRangeResult, err := rdb.LRange(ctx, \"mylist\", 0, -1).Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(lRangeResult) // >>> [one two]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> rpop = asyncCommands.rpush(\"mylist\", \"one\", \"two\", \"three\", \"four\", \"five\")\n                    .thenCompose(res18 -> {\n                        System.out.println(res18); // >>> 5\n\n                        return asyncCommands.rpop(\"mylist\");\n                    }).thenCompose(res19 -> {\n                        System.out.println(res19); // >>> five\n\n                        return asyncCommands.rpop(\"mylist\", 2);\n                    }).thenCompose(res20 -> {\n                        System.out.println(res20); // >>> [four, three]\n\n                        return asyncCommands.lrange(\"mylist\", 0, -1);\n                    })\n                    .thenAccept(res21 -> System.out.println(res21)) // >>> [one, two]\n                    .toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "Mono<Void> rpop = reactiveCommands.rpush(\"mylist\", \"one\", \"two\", \"three\", \"four\", \"five\").doOnNext(res18 -> {\n                System.out.println(res18); // >>> 5\n            }).flatMap(res18 -> reactiveCommands.rpop(\"mylist\")).doOnNext(res19 -> {\n                System.out.println(res19); // >>> five\n            }).flatMap(res19 -> reactiveCommands.rpop(\"mylist\", 2).collectList()).doOnNext(res20 -> {\n                System.out.println(res20); // >>> [four, three]\n            }).flatMap(res20 -> reactiveCommands.lrange(\"mylist\", 0, -1).collectList()).doOnNext(res21 -> {\n                System.out.println(res21); // >>> [one, two]\n            }).then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "long rPopResult1 = jedis.rpush(\n            \"mylist\", \"one\", \"two\", \"three\", \"four\", \"five\"\n        );\n        System.out.println(rPopResult1); // >>> 5\n\n        String rPopResult2 = jedis.rpop(\"mylist\");\n        System.out.println(rPopResult2); // >>> five\n\n        List<String> rPopResult3 = jedis.rpop(\"mylist\", 2);\n        System.out.println(rPopResult3); // >>> [four, three]\n\n        List<String> rPopResult4 = jedis.lrange(\"mylist\", 0, -1);\n        System.out.println(rPopResult4); // >>> [one, two]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "javascript",
      "code": "const res21 = await client.rPush('mylist', [\"one\", \"two\", \"three\", \"four\", \"five\"]);\nconsole.log(res21); // 5\n\nconst res22 = await client.rPop('mylist');\nconsole.log(res22); // 'five'\n\nconst res23 = await client.rPopCount('mylist', 2);\nconsole.log(res23); // [ 'four', 'three' ]\n\nconst res24 = await client.lRange('mylist', 0, -1);\nconsole.log(res24); // [ 'one', 'two' ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "javascript",
      "code": "const res21 = await redis.rpush('mylist', 'one', 'two', 'three', 'four', 'five');\nconsole.log(res21); // >>> 5\n\nconst res22 = await redis.rpop('mylist');\nconsole.log(res22); // >>> five\n\nconst res23 = await redis.rpop('mylist', 2);\nconsole.log(res23); // >>> ['four', 'three']\n\nconst res24 = await redis.lrange('mylist', 0, -1);\nconsole.log(res24); // >>> ['one', 'two']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "const res21 = await client.rPush('mylist', [\"one\", \"two\", \"three\", \"four\", \"five\"]);\nconsole.log(res21); // 5\n\nconst res22 = await client.rPop('mylist');\nconsole.log(res22); // 'five'\n\nconst res23 = await client.rPopCount('mylist', 2);\nconsole.log(res23); // [ 'four', 'three' ]\n\nconst res24 = await client.lRange('mylist', 0, -1);\nconsole.log(res24); // [ 'one', 'two' ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "const res21 = await redis.rpush('mylist', 'one', 'two', 'three', 'four', 'five');\nconsole.log(res21); // >>> 5\n\nconst res22 = await redis.rpop('mylist');\nconsole.log(res22); // >>> five\n\nconst res23 = await redis.rpop('mylist', 2);\nconsole.log(res23); // >>> ['four', 'three']\n\nconst res24 = await redis.lrange('mylist', 0, -1);\nconsole.log(res24); // >>> ['one', 'two']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "php",
      "code": "$res21 = $r->rpush('mylist', 'one', 'two', 'three', 'four', 'five');\n        echo $res21 . PHP_EOL;\n        // >>> 5\n\n        $res22 = $r->rpop('mylist');\n        echo $res22 . PHP_EOL;\n        // >>> five\n\n        $res23 = $r->rpop('mylist', 2);\n        echo json_encode($res23) . PHP_EOL;\n        // >>> [\"four\",\"three\"]\n\n        $res24 = $r->lrange('mylist', 0, -1);\n        echo json_encode($res24) . PHP_EOL;\n        // >>> [\"one\",\"two\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "python",
      "code": "res18 = r.rpush(\"mylist\", *[\"one\", \"two\", \"three\", \"four\", \"five\"])\nprint(res18) # >>> 5\n\nres19 = r.rpop(\"mylist\")\nprint(res19) # >>> \"five\"\n\nres20 = r.rpop(\"mylist\", 2)\nprint(res20) # >>> ['four', 'three']\n\nres21 = r.lrange(\"mylist\", 0, -1)\nprint(res21)  # >>> [ \"one\", \"two\" ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "ruby",
      "code": "res21 = r.rpush('mylist', ['one', 'two', 'three', 'four', 'five'])\nputs res21 # >>> 5\n\nres22 = r.rpop('mylist')\nputs res22 # >>> five\n\nres23 = r.rpop('mylist', 2)\nputs res23.inspect # >>> [\"four\", \"three\"]\n\nres24 = r.lrange('mylist', 0, -1)\nputs res24.inspect # >>> [\"one\", \"two\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "rust",
      "code": "if let Ok(res21) = r.rpush(\"mylist\", &[\"one\", \"two\", \"three\", \"four\", \"five\"]).await {\n            let res21: i32 = res21;\n            println!(\"{res21}\"); // >>> 5\n        }\n\n        if let Ok(res22) = r.rpop(\"mylist\", None).await {\n            let res22: String = res22;\n            println!(\"{res22}\"); // >>> five\n        }\n\n        if let Ok(res23) = r.rpop(\"mylist\", NonZeroUsize::new(2)).await {\n            let res23: Vec<String> = res23;\n            println!(\"{res23:?}\"); // >>> [\"four\", \"three\"]\n        }\n\n        if let Ok(res24) = r.lrange(\"mylist\", 0, -1).await {\n            let res24: Vec<String> = res24;\n            println!(\"{res24:?}\"); // >>> [\"one\", \"two\"]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "rust",
      "code": "if let Ok(res21) = r.rpush(\"mylist\", &[\"one\", \"two\", \"three\", \"four\", \"five\"]) {\n            let res21: i32 = res21;\n            println!(\"{res21}\"); // >>> 5\n        }\n\n        if let Ok(res22) = r.rpop(\"mylist\", None) {\n            let res22: String = res22;\n            println!(\"{res22}\"); // >>> five\n        }\n\n        if let Ok(res23) = r.rpop(\"mylist\", NonZeroUsize::new(2)) {\n            let res23: Vec<String> = res23;\n            println!(\"{res23:?}\"); // >>> [\"four\", \"three\"]\n        }\n\n        if let Ok(res24) = r.lrange(\"mylist\", 0, -1) {\n            let res24: Vec<String> = res24;\n            println!(\"{res24:?}\"); // >>> [\"one\", \"two\"]\n        }",
      "section_id": "examples"
    }
  ]
}
