{"id":15026102,"url":"https://github.com/averias/phpredis-json","last_synced_at":"2025-10-15T16:20:08.034Z","repository":{"id":54276081,"uuid":"220124643","full_name":"averias/phpredis-json","owner":"averias","description":"A PHP client for RedisJSON module using phpredis extension","archived":false,"fork":false,"pushed_at":"2021-02-27T13:20:02.000Z","size":141,"stargazers_count":34,"open_issues_count":5,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-09-19T22:37:47.194Z","etag":null,"topics":["client-library","json","php-library","php72","redis","redisjson"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/averias.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-07T01:27:35.000Z","updated_at":"2025-01-21T12:15:15.000Z","dependencies_parsed_at":"2022-08-13T10:40:52.610Z","dependency_job_id":null,"html_url":"https://github.com/averias/phpredis-json","commit_stats":null,"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"purl":"pkg:github/averias/phpredis-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averias%2Fphpredis-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averias%2Fphpredis-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averias%2Fphpredis-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averias%2Fphpredis-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/averias","download_url":"https://codeload.github.com/averias/phpredis-json/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/averias%2Fphpredis-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279091808,"owners_count":26101586,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["client-library","json","php-library","php72","redis","redisjson"],"created_at":"2024-09-24T20:03:45.390Z","updated_at":"2025-10-15T16:20:07.998Z","avatar_url":"https://github.com/averias.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Test Coverage](https://api.codeclimate.com/v1/badges/0139a26763ee4a0c3343/test_coverage)](https://codeclimate.com/github/averias/phpredis-json/test_coverage)\n[![Maintainability](https://api.codeclimate.com/v1/badges/0139a26763ee4a0c3343/maintainability)](https://codeclimate.com/github/averias/phpredis-json/maintainability)\n[![Build Status](https://travis-ci.org/averias/phpredis-json.svg?branch=master)](https://travis-ci.org/averias/phpredis-json)\n[![Packagist Version](https://img.shields.io/packagist/v/averias/phpredis-json.svg)](https://packagist.org/packages/averias/phpredis-json)\n[![GitHub](https://img.shields.io/github/license/averias/phpredis-json.svg)](https://github.com/averias/phpredis-json)\n\n# Phpredis-JSON\nRedisJson with the PHP Redis extension [phpredis](https://github.com/phpredis/phpredis).\n\n## Intro\nPhpredis-JSON provides a full set of commands for [RedisJson Module](https://oss.redislabs.com/redisjson/). \nIt's built on top of the `phpredis` and use it as Redis client, \nso you can also take advantage of some of the features included in `phpredis` as Redis client.\n\n## Why?\nAlthough you can issue RedisJSON commands by using some PHP Redis clients which provides you the ability to send \nraw Redis commands, Phpredis-JSON:\n- avoids you the task of encoding your PHP data structures to JSON before sending them to Redis \nand decode the JSON responses back from Redis\n- it validates JSON encode/decode and throw a proper exception in case of failure\n- provides a set of commands as methods of the RedisJSON client  \n\n## Requirements\n- Redis server 4.0+ version (RedisJson Module is only available from Redis 4.0+)\n- RedisJson Module installed on Redis server as specified in [Building and loading RedisJSON Module](https://oss.redislabs.com/redisjson/#building-and-loading-the-module)\n- PHP 7.2+ with PHP Redis extension 5 installed\n\n## Usage\n```php\n\u003c?php\n\nuse Averias\\RedisJson\\Enum\\JsonCommands;\nuse Averias\\RedisJson\\Exception\\ResponseException;\nuse Averias\\RedisJson\\Factory\\RedisJsonClientFactory;\n\n// *** get a RedisJsonClient ***\n$redisJsonClientFactory = new RedisJsonClientFactory();\n/**\n * creates a RedisJsonClient with default connection params:\n * [\n *     'host' =\u003e '127.0.0.1',\n *     'port' =\u003e 6379,\n *     'timeout' =\u003e 0.0, // seconds\n *     'retryInterval' =\u003e 15 // milliseconds\n *     'readTimeout' =\u003e 2, // seconds\n *     'persistenceId' =\u003e null // string for persistent connections, null for no persistent ones\n *     'database' =\u003e 0 // Redis database index [0..15]\n * ]\n */\n$defaultClient = $redisJsonClientFactory-\u003ecreateClient();\n\n// creates a configured RedisJsonClient\n$client = $redisJsonClientFactory-\u003ecreateClient([\n    'host' =\u003e '127.0.0.1',\n    'port' =\u003e 6390,\n    'timeout' =\u003e 2,\n    'database' =\u003e 15\n]);\n\n// *** Redis JSON commands ***\n$result = $client-\u003ejsonSet('people', [\"name\" =\u003e \"gafael\", \"age\" =\u003e 12]);\necho ($result === true ? 'true' : 'false') . PHP_EOL; // true\n\n$result = $client-\u003ejsonGet('people'); // $result = [\"name\":\"gafael\",\"age\":12]\necho json_encode($result) . PHP_EOL; // {\"name\":\"gafael\",\"age\":12}\n\n$result =  $client-\u003ejsonGet('people', '.name');\necho $result . PHP_EOL; // \"gafael\"\n\n$result =  $client-\u003ejsonGet('people', '.age');\necho $result . PHP_EOL; // 12\n\n// \"nonexistent\" key does not exist, so a ResponseException is thrown\ntry {\n    $result = $client-\u003ejsonGet('nonexistent');\n    echo $result . PHP_EOL;\n} catch (ResponseException $e) {\n    echo \"key nonexistent does not exist\" . PHP_EOL;\n}\n\n// *** you can also send RedisJSON command as raw commands using \"RedisJsonClient::executeRawCommand\"  ***\n// you will send\n$result =  $client-\u003eexecuteRawCommand(JsonCommands::SET, 'people', '.colors', '[\"blue\", \"green\"]');\necho $result . PHP_EOL; // 'OK'\n\n// and receive JSON values\n$result =  $client-\u003eexecuteRawCommand(JsonCommands::GET, 'people', '.');\necho $result . PHP_EOL; // {\"name\":\"gafael\",\"age\":12,\"colors\":[\"blue\",\"green\"]}\n\n\n// *** you can also issue redis commands and use RedisJsonClient as \"phpredis\" client:\necho $client-\u003ehset('hash-key', 'age', 34) . PHP_EOL; // 0\necho $client-\u003ehget('hash-key', 'age') . PHP_EOL; // 34\n\n// $ret = [true,\"val1\",true,\"val2\"]\n$ret = $client-\u003emulti()\n    -\u003eset('key1', 'val1')\n    -\u003eget('key1')\n    -\u003eset('key2', 'val2')\n    -\u003eget('key2')\n    -\u003eexec();\n\necho json_encode($ret) . PHP_EOL;\n\n```\n\n## Commands\n- **RedisJSON commands:** please take a look to the list of [phpredis-json commands](https://github.com/averias/phpredis-json/blob/master/docs/JSON-COMMANDS.md)\n- **Phpredis commands:** you can send Redis commands as specified in [phpredis documentation](https://github.com/phpredis/phpredis#table-of-contents)\n- **Raw commands:** you can send whatever you want to Redis by using `RedisJsonClient::executeRawCommand`:\n```php\n// raw Redis JSON command\n$client-\u003eexecuteRawCommand(JsonCommands::GET, 'people', '.');\n\n// raw Redis command\n$client-\u003eexecuteRawCommand('hget, 'hash-key', 'foo');\n``` \n\n## Tests\n#### On a local Redis server 4.0+ with RedisJSON module and Redis extension 5 installed\nFrom console run the following command from the root directory of this project:\n\n`./vendor/bin/phpunit`\n\nif you don't have configured your local Redis server in 127.0.0.1:6379 you can set REDIS_TEST_SERVER and REDIS_TEST_PORT \nand REDIS_TEST_DATABASE in `./phpunit.xml` file with your local Redis host, port and database before running the above \ncommand.\n  \n#### Docker\nHaving Docker installed, run the following command in the root directory of this project:\n\n`bash run-tests-docker.sh`\n\nby running the above bash script, two docker services will be built, one with PHP 7.2 with xdebug and redis extensions\nenabled and another with the image of `redislab\\rejson:1.0.4` (Redis server 5 with RedisJson module installed). \nThen the tests will run inside `phpredis-json` docker service container and finally both container will be stopped.\n\n## Examples\n- [Usage](https://github.com/averias/phpredis-json/blob/master/examples/usage.php)\n- [Commands](https://github.com/averias/phpredis-json/blob/master/examples/commands.php)\n\n## License\nPhpredis-Json code is distributed under MIT license, see [LICENSE](https://github.com/averias/phpredis-json/blob/master/LICENSE) \nfile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faverias%2Fphpredis-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faverias%2Fphpredis-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faverias%2Fphpredis-json/lists"}