{
  "schema_version": 2,
  "id": "develop/clients/php",
  "title": "Predis guide (PHP)",
  "url": "https://redis.io/docs/latest/develop/clients/php/",
  "summary": "Connect your PHP application to a Redis database",
  "aliases": [
    "/develop/connect/clients/php",
    "/connect/clients/php/",
    "/clients/php/",
    "/develop/clients/predis"
  ],
  "tags": [
    "docs",
    "develop",
    "stack",
    "oss",
    "rs",
    "rc",
    "oss",
    "kubernetes",
    "clients"
  ],
  "last_updated": "2026-09-09T09:49:12+01:00",
  "children": [
    {
      "id": "develop/clients/php/connect",
      "summary": "Connect your PHP application to a Redis database",
      "title": "Connect to the server",
      "url": "https://redis.io/docs/latest/develop/clients/php/connect/"
    },
    {
      "id": "develop/clients/php/queryjson",
      "summary": "Learn how to use Redis Search with JSON and hash documents.",
      "title": "Index and query documents",
      "url": "https://redis.io/docs/latest/develop/clients/php/queryjson/"
    },
    {
      "id": "develop/clients/php/vecsearch",
      "summary": "Learn how to index and query vector embeddings with Redis",
      "title": "Index and query vectors",
      "url": "https://redis.io/docs/latest/develop/clients/php/vecsearch/"
    },
    {
      "id": "develop/clients/php/transpipe",
      "summary": "Learn how to use Redis pipelines and transactions",
      "title": "Pipelines and transactions",
      "url": "https://redis.io/docs/latest/develop/clients/php/transpipe/"
    },
    {
      "id": "develop/clients/php/vecsets",
      "summary": "Index and query embeddings with Redis vector sets",
      "title": "Vector set embeddings",
      "url": "https://redis.io/docs/latest/develop/clients/php/vecsets/"
    },
    {
      "id": "develop/clients/php/prob",
      "summary": "Learn how to use approximate calculations with Redis.",
      "title": "Probabilistic data types",
      "url": "https://redis.io/docs/latest/develop/clients/php/prob/"
    },
    {
      "id": "develop/clients/php/error-handling",
      "summary": "Learn how to handle errors when using Predis.",
      "title": "Error handling",
      "url": "https://redis.io/docs/latest/develop/clients/php/error-handling/"
    }
  ],
  "page_type": "content",
  "content_hash": "73894555131365fda0c751e6f76cec138218354e3bf5800941e5a57d0c941da4",
  "sections": [
    {
      "id": "install",
      "title": "Install",
      "role": "setup",
      "text": "Use [Composer](https://getcomposer.org/) to install the `Predis` library\nwith the following command line:\n\n[code example]"
    },
    {
      "id": "connect-and-test",
      "title": "Connect and test",
      "role": "content",
      "text": "Connect to a locally-running server on the standard port (6379)\nwith the following code:\n\nFoundational: Connect to a Redis server and establish a client connection\n\n**Difficulty:** Beginner\n\n**Available in:** PHP\n\n##### PHP\n\n[code example]\n\n\n\nStore and retrieve a simple string to test the connection:\n\nFoundational: Set and retrieve string values using SET and GET commands\n\n**Difficulty:** Beginner\n\n**Available in:** PHP\n\n##### PHP\n\n[code example]\n\n\n\nStore and retrieve a [hash](https://redis.io/docs/latest/develop/data-types/hashes)\nobject:\n\nFoundational: Store and retrieve hash data structures using HSET and HGETALL\n\n**Difficulty:** Beginner\n\n**Available in:** PHP\n\n##### PHP\n\n[code example]"
    },
    {
      "id": "more-information",
      "title": "More information",
      "role": "content",
      "text": "The [Predis wiki on Github](https://github.com/predis/predis/wiki) has\ninformation about the different connection options you can use.\n\nSee also the pages in this section for more information and examples:"
    }
  ],
  "examples": [
    {
      "id": "install-ex0",
      "language": "bash",
      "code": "composer require predis/predis",
      "section_id": "install"
    },
    {
      "id": "connect-and-test-ex0",
      "language": "php",
      "code": "<?php\n\nrequire 'vendor/autoload.php';\n\nuse Predis\\Client as PredisClient;\n\n$r = new PredisClient([\n                'scheme'   => 'tcp',\n                'host'     => '127.0.0.1',\n                'port'     => 6379,\n                'password' => '',\n                'database' => 0,\n            ]);",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex1",
      "language": "php",
      "code": "echo $r->set('foo', 'bar'), PHP_EOL;\n// >>> OK\n\necho $r->get('foo'), PHP_EOL;\n// >>> bar",
      "section_id": "connect-and-test"
    },
    {
      "id": "connect-and-test-ex2",
      "language": "php",
      "code": "$r->hset('user-session:123', 'name', 'John');\n$r->hset('user-session:123', 'surname', 'Smith');\n$r->hset('user-session:123', 'company', 'Redis');\n$r->hset('user-session:123', 'age', 29);\n\necho var_export($r->hgetall('user-session:123')), PHP_EOL;\n/* >>>\narray (\n  'name' => 'John',\n  'surname' => 'Smith',\n  'company' => 'Redis',\n  'age' => '29',\n)\n*/",
      "section_id": "connect-and-test"
    }
  ]
}
