{"id":14966340,"url":"https://github.com/yiisoft/cache-redis","last_synced_at":"2025-10-19T09:31:16.982Z","repository":{"id":38213386,"uuid":"424661369","full_name":"yiisoft/cache-redis","owner":"yiisoft","description":"Redis adapter for cache","archived":false,"fork":false,"pushed_at":"2024-04-03T22:55:20.000Z","size":44,"stargazers_count":9,"open_issues_count":2,"forks_count":4,"subscribers_count":17,"default_branch":"master","last_synced_at":"2024-04-15T03:06:21.893Z","etag":null,"topics":["cache","hacktoberfest","psr-16","redis","redis-cache","yii3"],"latest_commit_sha":null,"homepage":"https://www.yiiframework.com/","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yiisoft.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"open_collective":"yiisoft","github":["yiisoft"]}},"created_at":"2021-11-04T16:18:45.000Z","updated_at":"2024-04-13T16:28:46.000Z","dependencies_parsed_at":"2024-04-11T03:44:44.336Z","dependency_job_id":null,"html_url":"https://github.com/yiisoft/cache-redis","commit_stats":{"total_commits":31,"total_committers":9,"mean_commits":"3.4444444444444446","dds":0.7419354838709677,"last_synced_commit":"85767c4db5fd980006821773331815396b253acf"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":"yiisoft/package-template","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-redis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-redis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-redis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yiisoft%2Fcache-redis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yiisoft","download_url":"https://codeload.github.com/yiisoft/cache-redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219869926,"owners_count":16555204,"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","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":["cache","hacktoberfest","psr-16","redis","redis-cache","yii3"],"created_at":"2024-09-24T13:36:14.692Z","updated_at":"2025-10-19T09:31:11.717Z","avatar_url":"https://github.com/yiisoft.png","language":"PHP","funding_links":["https://opencollective.com/yiisoft","https://github.com/sponsors/yiisoft"],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/yiisoft\" target=\"_blank\"\u003e\n        \u003cimg src=\"https://yiisoft.github.io/docs/images/yii_logo.svg\" height=\"100px\" alt=\"Yii\"\u003e\n    \u003c/a\u003e\n    \u003ch1 align=\"center\"\u003eYii Caching Library - Redis Handler\u003c/h1\u003e\n    \u003cbr\u003e\n\u003c/p\u003e\n\n[![Latest Stable Version](https://poser.pugx.org/yiisoft/cache-redis/v/stable.png)](https://packagist.org/packages/yiisoft/cache-redis)\n[![Total Downloads](https://poser.pugx.org/yiisoft/cache-redis/downloads.png)](https://packagist.org/packages/yiisoft/cache-redis)\n[![Build status](https://github.com/yiisoft/cache-redis/workflows/build/badge.svg)](https://github.com/yiisoft/cache-redis/actions?query=workflow%3Abuild)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/yiisoft/cache-redis/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/cache-redis/?branch=master)\n[![Code Coverage](https://scrutinizer-ci.com/g/yiisoft/cache-redis/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/yiisoft/cache-redis/?branch=master)\n[![Mutation testing badge](https://img.shields.io/endpoint?style=flat\u0026url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Fcache-redis%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/cache-redis/master)\n[![static analysis](https://github.com/yiisoft/cache-redis/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/cache-redis/actions?query=workflow%3A%22static+analysis%22)\n[![type-coverage](https://shepherd.dev/github/yiisoft/cache-redis/coverage.svg)](https://shepherd.dev/github/yiisoft/cache-redis)\n\nThis package provides the [Redis](https://redis.io/) handler and\nimplements [PSR-16](https://www.php-fig.org/psr/psr-16/) cache.\n\n## Requirements\n\n- PHP 8.0 or higher.\n\n## Installation\n\nThe package could be installed with [Composer](https://getcomposer.org):\n\n```shell\ncomposer require yiisoft/cache-redis\n```\n\n## General usage\n\nFor more information about the client instance and connection configuration,\nsee the documentation of the [predis/predis](https://github.com/predis/predis) package.\n\n```php\n/**\n * @var \\Predis\\ClientInterface $client Predis client instance to use.\n */\n$cache = new \\Yiisoft\\Cache\\Redis\\RedisCache($client);\n```\n\nThe package does not contain any additional functionality for interacting with the cache,\nexcept those defined in the [PSR-16](https://www.php-fig.org/psr/psr-16/) interface.\n\n```php\n$parameters = ['user_id' =\u003e 42];\n$key = 'demo';\n\n// try retrieving $data from cache\n$data = $cache-\u003eget($key);\n\nif ($data === null) {\n    // $data is not found in cache, calculate it from scratch\n    $data = calculateData($parameters);\n    \n    // store $data in cache for an hour so that it can be retrieved next time\n    $cache-\u003eset($key, $data, 3600);\n}\n\n// $data is available here\n```\n\nIn order to delete value you can use:\n\n```php\n$cache-\u003edelete($key);\n// Or all cache\n$cache-\u003eclear();\n```\n\nTo work with values in a more efficient manner, batch operations should be used:\n\n- `getMultiple()`\n- `setMultiple()`\n- `deleteMultiple()`\n\nThis package can be used as a cache handler for the [Yii Caching Library](https://github.com/yiisoft/cache).\n\n## Redis cluster supported\n\nThe package implements [Redis cluster](https://redis.io/docs/management/scaling/) support via `Predis` package.\n\nFor example, if your cluster configuration has three master nodes and three slave nodes, your client configuration might look like this:\n\n```php\n$client = new \\Predis\\Client([\n        ['host' =\u003e 'redis-node-1', 'port' =\u003e 'redis-node-port-1',],\n        ['host' =\u003e 'redis-node-2', 'port' =\u003e 'redis-node-port-2',],\n        ['host' =\u003e 'redis-node-3', 'port' =\u003e 'redis-node-port-3',],\n        ['host' =\u003e 'redis-node-4', 'port' =\u003e 'redis-node-port-4',],\n        ['host' =\u003e 'redis-node-5', 'port' =\u003e 'redis-node-port-5',],\n        ['host' =\u003e 'redis-node-6', 'port' =\u003e 'redis-node-port-6',],\n    ],\n    [\n        'cluster' =\u003e 'redis',\n        'parameters' =\u003e [\n            'password' =\u003e 'Password',\n        ],\n    ]\n);\n$cache = new \\Yiisoft\\Cache\\Redis\\RedisCache($client);\n```\n\nPredis will route commands on its own when specifying Redis nodes in the cluster to the appropriate nodes depending on the keys that are specified in the commands.\n\nYou can implement `\\Predis\\Distribution\\DistributorInterface` to create their own distributors used by the client to distribute keys among a cluster of servers.\n\nThen your config might look like this:\n\n```php\n$client = new \\Predis\\Client([\n        ['host' =\u003e 'redis-node-1', 'port' =\u003e 'redis-node-port-1',],\n        ['host' =\u003e 'redis-node-2', 'port' =\u003e 'redis-node-port-2',],\n        ['host' =\u003e 'redis-node-3', 'port' =\u003e 'redis-node-port-3',],\n        ['host' =\u003e 'redis-node-4', 'port' =\u003e 'redis-node-port-4',],\n        ['host' =\u003e 'redis-node-5', 'port' =\u003e 'redis-node-port-5',],\n        ['host' =\u003e 'redis-node-6', 'port' =\u003e 'redis-node-port-6',],\n    ],\n    [\n        'cluster' =\u003e static function () {\n            $distributor = new \\CustomDistributor(); // Your custom distributor\n            $strategy = new \\Predis\\Cluster\\PredisStrategy($distributor);\n\n            return new \\Predis\\Connection\\Cluster\\PredisCluster($strategy);\n        },\n        'parameters' =\u003e [\n            'password' =\u003e 'Password',\n        ],\n    ]\n);\n```\n\n## Documentation\n\n- [Internals](docs/internals.md)\n\nIf you need help or have a question, the [Yii Forum](https://forum.yiiframework.com/c/yii-3-0/63) is a good place for that.\nYou may also check out other [Yii Community Resources](https://www.yiiframework.com/community).\n\n## License\n\nThe Yii Caching Library - Redis Handler is free software. It is released under the terms of the BSD License.\nPlease see [`LICENSE`](./LICENSE.md) for more information.\n\nMaintained by [Yii Software](https://www.yiiframework.com/).\n\n## Support the project\n\n[![Open Collective](https://img.shields.io/badge/Open%20Collective-sponsor-7eadf1?logo=open%20collective\u0026logoColor=7eadf1\u0026labelColor=555555)](https://opencollective.com/yiisoft)\n\n## Follow updates\n\n[![Official website](https://img.shields.io/badge/Powered_by-Yii_Framework-green.svg?style=flat)](https://www.yiiframework.com/)\n[![Twitter](https://img.shields.io/badge/twitter-follow-1DA1F2?logo=twitter\u0026logoColor=1DA1F2\u0026labelColor=555555?style=flat)](https://twitter.com/yiiframework)\n[![Telegram](https://img.shields.io/badge/telegram-join-1DA1F2?style=flat\u0026logo=telegram)](https://t.me/yii3en)\n[![Facebook](https://img.shields.io/badge/facebook-join-1DA1F2?style=flat\u0026logo=facebook\u0026logoColor=ffffff)](https://www.facebook.com/groups/yiitalk)\n[![Slack](https://img.shields.io/badge/slack-join-1DA1F2?style=flat\u0026logo=slack)](https://yiiframework.com/go/slack)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fcache-redis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyiisoft%2Fcache-redis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyiisoft%2Fcache-redis/lists"}