{"id":13699743,"url":"https://github.com/mix-php/redis","last_synced_at":"2025-10-28T08:43:18.794Z","repository":{"id":57017834,"uuid":"162685273","full_name":"mix-php/redis","owner":"mix-php","description":"PHP Redis for use in multiple execution environments, with support for FPM, CLI, Swoole, WorkerMan, and optional connection pool (coroutine) / 可在各种环境中使用的 PHP Redis，支持 FPM、CLI、Swoole、WorkerMan，可选的连接池 (协程)","archived":false,"fork":false,"pushed_at":"2023-04-04T08:17:08.000Z","size":110,"stargazers_count":5,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T20:51:00.791Z","etag":null,"topics":["mix","pool","redis","swoole","workerman"],"latest_commit_sha":null,"homepage":"https://openmix.org/mix-php","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mix-php.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-12-21T08:06:00.000Z","updated_at":"2024-12-16T03:13:33.000Z","dependencies_parsed_at":"2024-01-12T20:57:06.427Z","dependency_job_id":null,"html_url":"https://github.com/mix-php/redis","commit_stats":{"total_commits":59,"total_committers":1,"mean_commits":59.0,"dds":0.0,"last_synced_commit":"3421f95fbe762bf5ddacb9dc67f5b93ad7f16e3f"},"previous_names":[],"tags_count":35,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fredis","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fredis/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fredis/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mix-php%2Fredis/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mix-php","download_url":"https://codeload.github.com/mix-php/redis/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248647257,"owners_count":21139081,"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":["mix","pool","redis","swoole","workerman"],"created_at":"2024-08-02T20:00:42.755Z","updated_at":"2025-10-28T08:43:18.686Z","avatar_url":"https://github.com/mix-php.png","language":"PHP","readme":"\u003e OpenMix 出品：[https://openmix.org](https://openmix.org/mix-php)\n\n# Mix Redis\n\nPHP Redis for use in multiple execution environments, with support for FPM, CLI, Swoole, WorkerMan, and optional\nconnection pool (coroutine)\n\n可在各种环境中使用的 PHP Redis，支持 FPM、CLI、Swoole、WorkerMan，可选的连接池 (协程)\n\n## 技术交流\n\n知乎：https://www.zhihu.com/people/onanying    \n官方QQ群：[284806582](https://shang.qq.com/wpa/qunwpa?idkey=b3a8618d3977cda4fed2363a666b081a31d89e3d31ab164497f53b72cf49968a)\n, [825122875](http://shang.qq.com/wpa/qunwpa?idkey=d2908b0c7095fc7ec63a2391fa4b39a8c5cb16952f6cfc3f2ce4c9726edeaf20)\n敲门暗号：redis\n\n## Installation\n\n```\ncomposer require mix/redis\n```\n\n## Quick start\n\n注意：[协程环境中，不可在并发请求中使用单例](https://openmix.org/mix-php/docs/3.0/#/zh-cn/instructions?id=%e5%8d%8f%e7%a8%8b%e5%8d%95%e4%be%8b%e5%ae%9e%e4%be%8b%e5%8c%96)\n\n```php\n$rds = new Mix\\Redis\\Redis('127.0.0.1', 6379, 'password', 0);\n\n$rds-\u003eset('foo', 'bar');\n$value = $rds-\u003eget('foo');\n```\n\n## Start Pool\n\n在 `Swoole` 协程环境中，启动连接池\n\n```php\n$maxOpen = 50;        // 最大开启连接数\n$maxIdle = 20;        // 最大闲置连接数\n$maxLifetime = 3600;  // 连接的最长生命周期\n$waitTimeout = 0.0;   // 从池获取连接等待的时间, 0为一直等待\n$rds-\u003estartPool($maxOpen, $maxIdle, $maxLifetime, $waitTimeout);\nSwoole\\Runtime::enableCoroutine(); // 必须放到最后，防止触发协程调度导致异常\n```\n\n连接池统计\n\n```php\n$rds-\u003epoolStats(); // array, fields: total, idle, active\n```\n\n## Transaction Multi \u0026 Pipeline\n\nMulti\n\n事务块内的多条命令会按照先后顺序被放进一个队列当中，最后由exec命令原子性(atomic)地执行。\n\n```php\n$tx = $rds-\u003emulti();\n$tx-\u003eset('foo', 'bar');\n$tx-\u003eset('foo1', 'bar1');\n$ret = $tx-\u003eexec();\n```\n\nPipeline\n\n客户端将执行的命令写入到缓冲中，最后由exec命令一次性发送给redis执行返回。\n\n```php\n$tx = $rds-\u003epipeline();\n$tx-\u003eset('foo', 'bar');\n$tx-\u003eset('foo1', 'bar1');\n$ret = $tx-\u003eexec();\n```\n\n## Transaction Watch\n\n监听值的变化，如果执行时有变化则事务失败，无变化则事务成功。\n\n```php\n$tx = $rds-\u003ewatch('foo');\n$tx-\u003eincr('foo');\n$ret = $tx-\u003eexec();\n```\n\n## Logger\n\n日志记录器，配置后可打印全部SQL信息\n\n```php\n$db-\u003esetLogger($logger);\n```\n\n`$logger` 需实现 `Mix\\Redis\\LoggerInterface`\n\n```php\ninterface LoggerInterface\n{\n    public function trace(float $time, string $cmd, array $args, ?\\Throwable $exception): void;\n}\n```\n\n## License\n\nApache License Version 2.0, http://www.apache.org/licenses/\n","funding_links":[],"categories":["Frameworks"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fredis","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmix-php%2Fredis","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmix-php%2Fredis/lists"}