{
  "schema_version": 2,
  "id": "commands/lpush",
  "title": "LPUSH",
  "url": "https://redis.io/docs/latest/commands/lpush/",
  "summary": "Prepends one or more elements to a list. Creates the key if it doesn't exist.",
  "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": "0d6e639264e236665093e2fb98865de93a6a1e5456f3a0f5c5b7a8af2b66a09a",
  "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>\n\n<details open><summary><code>element [element ...]</code></summary>\n\nOne or more values to prepend to the list.\n\n</details>"
    },
    {
      "id": "examples",
      "title": "Examples",
      "role": "example",
      "text": "Foundational: Add one or more elements to the head of a list using LPUSH (creates list if needed, returns new list length)\n\n**Difficulty:** Beginner\n\n**Commands:** LPUSH, LRANGE\n\n**Complexity:**\n- LPUSH: O(1)\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\n[Integer reply](../../develop/reference/protocol-spec#integers): the length of the list after the push operation.\n\n**RESP3:**\n\n[Integer reply](../../develop/reference/protocol-spec#integers): the length of the list after the push operation."
    }
  ],
  "examples": [
    {
      "id": "examples-ex0",
      "language": "plaintext",
      "code": "redis> LPUSH mylist \"world\"\n(integer) 1\nredis> LPUSH mylist \"hello\"\n(integer) 2\nredis> LRANGE mylist 0 -1\n1) \"hello\"\n2) \"world\"",
      "section_id": "examples"
    },
    {
      "id": "examples-ex1",
      "language": "csharp",
      "code": "long lPushResult1 = db.ListLeftPush(\"mylist\", \"World\");\n        Console.WriteLine(lPushResult1); // >>> 1\n\n        long lPushResult2 = db.ListLeftPush(\"mylist\", \"Hello\");\n        Console.WriteLine(lPushResult2); // >>> 2\n\n        RedisValue[] lPushResult3 = db.ListRange(\"mylist\", 0, -1);\n        Console.WriteLine($\"[{string.Join(\", \", lPushResult3)}]\");\n        // >>> [Hello, World]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex2",
      "language": "go",
      "code": "lPushResult1, err := rdb.LPush(ctx, \"mylist\", \"World\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(lPushResult1) // >>> 1\n\n\tlPushResult2, err := rdb.LPush(ctx, \"mylist\", \"Hello\").Result()\n\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Println(lPushResult2) // >>> 2\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) // >>> [Hello World]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex3",
      "language": "java",
      "code": "CompletableFuture<Void> lpush = asyncCommands.lpush(\"mylist\", \"world\").thenCompose(res1 -> {\n                System.out.println(res1); // >>> 1\n\n                return asyncCommands.lpush(\"mylist\", \"hello\");\n            }).thenCompose(res2 -> {\n                System.out.println(res2); // >>> 2\n\n                return asyncCommands.lrange(\"mylist\", 0, -1);\n            })\n                    .thenAccept(res3 -> System.out.println(res3)) // >>> [hello, world]\n                    .toCompletableFuture();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex4",
      "language": "java",
      "code": "Mono<Void> lpush = reactiveCommands.lpush(\"mylist\", \"world\").doOnNext(res1 -> {\n                System.out.println(res1); // >>> 1\n            }).flatMap(res1 -> reactiveCommands.lpush(\"mylist\", \"hello\")).doOnNext(res2 -> {\n                System.out.println(res2); // >>> 2\n            }).flatMap(res2 -> reactiveCommands.lrange(\"mylist\", 0, -1).collectList()).doOnNext(res3 -> {\n                System.out.println(res3); // >>> [hello, world]\n            }).then();",
      "section_id": "examples"
    },
    {
      "id": "examples-ex5",
      "language": "java",
      "code": "long lPushResult1 = jedis.lpush(\"mylist\", \"World\");\n        System.out.println(lPushResult1); // >>> 1\n\n        long lPushResult2 = jedis.lpush(\"mylist\", \"Hello\");\n        System.out.println(lPushResult2); // >>> 2\n\n        List<String> lPushResult3 = jedis.lrange(\"mylist\", 0, -1);\n        System.out.println(lPushResult3);\n        // >>> [Hello, World]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex6",
      "language": "javascript",
      "code": "const res1 = await client.lPush('mylist', 'world');\nconsole.log(res1); // 1\n\nconst res2 = await client.lPush('mylist', 'hello');\nconsole.log(res2); // 2\n\nconst res3 = await client.lRange('mylist', 0, -1);\nconsole.log(res3); // [ 'hello', 'world' ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex7",
      "language": "javascript",
      "code": "const res1 = await redis.lpush('mylist', 'world');\nconsole.log(res1); // >>> 1\n\nconst res2 = await redis.lpush('mylist', 'hello');\nconsole.log(res2); // >>> 2\n\nconst res3 = await redis.lrange('mylist', 0, -1);\nconsole.log(res3); // >>> ['hello', 'world']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex8",
      "language": "javascript",
      "code": "const res1 = await client.lPush('mylist', 'world');\nconsole.log(res1); // 1\n\nconst res2 = await client.lPush('mylist', 'hello');\nconsole.log(res2); // 2\n\nconst res3 = await client.lRange('mylist', 0, -1);\nconsole.log(res3); // [ 'hello', 'world' ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex9",
      "language": "javascript",
      "code": "const res1 = await redis.lpush('mylist', 'world');\nconsole.log(res1); // >>> 1\n\nconst res2 = await redis.lpush('mylist', 'hello');\nconsole.log(res2); // >>> 2\n\nconst res3 = await redis.lrange('mylist', 0, -1);\nconsole.log(res3); // >>> ['hello', 'world']",
      "section_id": "examples"
    },
    {
      "id": "examples-ex10",
      "language": "php",
      "code": "$res1 = $r->lpush('mylist', 'world');\n        echo $res1 . PHP_EOL;\n        // >>> 1\n\n        $res2 = $r->lpush('mylist', 'hello');\n        echo $res2 . PHP_EOL;\n        // >>> 2\n\n        $res3 = $r->lrange('mylist', 0, -1);\n        echo json_encode($res3) . PHP_EOL;\n        // >>> [\"hello\",\"world\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex11",
      "language": "python",
      "code": "res1 = r.lpush(\"mylist\", \"world\")\nprint(res1) # >>> 1\n\nres2 = r.lpush(\"mylist\", \"hello\")\nprint(res2) # >>> 2\n\nres3 = r.lrange(\"mylist\", 0, -1)\nprint(res3)  # >>> [ \"hello\", \"world\" ]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex12",
      "language": "ruby",
      "code": "res1 = r.lpush('mylist', 'world')\nputs res1 # >>> 1\n\nres2 = r.lpush('mylist', 'hello')\nputs res2 # >>> 2\n\nres3 = r.lrange('mylist', 0, -1)\nputs res3.inspect # >>> [\"hello\", \"world\"]",
      "section_id": "examples"
    },
    {
      "id": "examples-ex13",
      "language": "rust",
      "code": "if let Ok(res1) = r.lpush(\"mylist\", \"world\").await {\n            let res1: i32 = res1;\n            println!(\"{res1}\"); // >>> 1\n        }\n\n        if let Ok(res2) = r.lpush(\"mylist\", \"hello\").await {\n            let res2: i32 = res2;\n            println!(\"{res2}\"); // >>> 2\n        }\n\n        if let Ok(res3) = r.lrange(\"mylist\", 0, -1).await {\n            let res3: Vec<String> = res3;\n            println!(\"{res3:?}\"); // >>> [\"hello\", \"world\"]\n        }",
      "section_id": "examples"
    },
    {
      "id": "examples-ex14",
      "language": "rust",
      "code": "if let Ok(res1) = r.lpush(\"mylist\", \"world\") {\n            let res1: i32 = res1;\n            println!(\"{res1}\"); // >>> 1\n        }\n\n        if let Ok(res2) = r.lpush(\"mylist\", \"hello\") {\n            let res2: i32 = res2;\n            println!(\"{res2}\"); // >>> 2\n        }\n\n        if let Ok(res3) = r.lrange(\"mylist\", 0, -1) {\n            let res3: Vec<String> = res3;\n            println!(\"{res3:?}\"); // >>> [\"hello\", \"world\"]\n        }",
      "section_id": "examples"
    }
  ]
}
