Skip to content

Commit 404a01b

Browse files
Fix #276: Added support for predis
- changed default value of yii\redis\Cache::$forceClusterMode to false - implemented yii\redis\ConnectionInterface in yii\redis\Connection - Updated minimum required PHP version to 8.1
1 parent 7eb5b43 commit 404a01b

File tree

82 files changed

+5995
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+5995
-293
lines changed

.github/workflows/build.yml

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,16 @@ jobs:
3131
- ubuntu-latest
3232

3333
php:
34-
- 8.1
35-
- 8.2
36-
- 8.3
37-
- 8.4
38-
39-
redis:
40-
- 6
41-
- 7
42-
- 8
43-
44-
services:
45-
redis:
46-
image: redis:${{ matrix.redis }}
47-
ports:
48-
- 6379:6379
49-
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=5
34+
- "8.1"
35+
- "8.2"
36+
- "8.3"
37+
- "8.4"
5038

5139
steps:
5240
- name: Checkout
53-
uses: actions/checkout@v4
54-
55-
- name: Install PHP with extensions
56-
uses: shivammathur/setup-php@v2
57-
with:
58-
php-version: ${{ matrix.php }}
59-
extensions: curl, intl, redis
60-
ini-values: date.timezone='UTC'
61-
tools: composer:v2, pecl
62-
63-
- name: Install dependencies with Composer
64-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
65-
66-
- name: Run tests with phpunit.
67-
if: matrix.php != '8.1'
68-
run: vendor/bin/phpunit --colors=always
69-
70-
- name: Run tests with phpunit and generate coverage.
71-
if: matrix.php == '8.1'
72-
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always
41+
uses: actions/checkout@v2
7342

74-
- name: Upload coverage to Codecov.
75-
if: matrix.php == '8.1'
76-
uses: codecov/codecov-action@v4
77-
with:
78-
token: ${{ secrets.CODECOV_TOKEN }}
79-
files: ./coverage.xml
43+
- name: PHP tests for PHP ${{ matrix.php }}
44+
run: |
45+
ls -al
46+
make test-sentinel v=${{ matrix.php }}

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
Yii Framework 2 redis extension Change Log
22
==========================================
33

4-
2.0.20 under development
4+
2.0.21 under development
55
------------------------
66

7+
- New #276: Added support for predis (antonshevelev)
8+
- New #276: Changed default value of yii\redis\Cache::$forceClusterMode to false (antonshevelev)
9+
- New #276: Implemented yii\redis\ConnectionInterface in yii\redis\Connection (antonshevelev)
10+
- New #276: Updated minimum required PHP version to 8.1 (antonshevelev)
11+
12+
13+
2.0.20 June 05, 2025
14+
--------------------
15+
16+
- Bug CVE-2025-48493: Prevent logging `AUTH` parameters when `YII_DEBUG` is off (samdark)
717
- Bug #270: Prevent null parameter on `mb_strlen` to avoid PHP 8.4 implicity nullable types deprecation (tehmaestro)
818

919

Makefile

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ clean:
3535
docker rm $(shell cat tests/dockerids/redis)
3636
rm tests/dockerids/redis
3737

38+
test-sentinel:
39+
make build
40+
PHP_VERSION=$(filter-out $@,$(MAKECMDGOALS)) docker compose -f tests/docker/docker-compose.yml build --pull yii2-redis-php
41+
PHP_VERSION=$(filter-out $@,$(MAKECMDGOALS)) docker compose -f tests/docker/docker-compose.yml up -d
42+
PHP_VERSION=$(filter-out $@,$(MAKECMDGOALS)) docker compose -f tests/docker/docker-compose.yml exec yii2-redis-php sh -c "composer update && vendor/bin/phpunit --coverage-clover=coverage.clover"
43+
44+
build: ## Build an image from a docker-compose file. Params: {{ v=8.1 }}. Default latest PHP 8.1
45+
PHP_VERSION=$(filter-out $@,$(v)) docker compose -f tests/docker/docker-compose.yml up -d --build
46+
47+
down: ## Stop and remove containers, networks
48+
docker compose -f tests/docker/docker-compose.yml down
49+

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,8 @@ return [
100100
]
101101
];
102102
```
103+
104+
Additional topics
105+
-----------------
106+
107+
* [predis support](predis.md)

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
],
2626
"require": {
2727
"php": ">=8.1",
28+
"yiisoft/yii2": "22.0.x-dev",
2829
"ext-openssl": "*",
29-
"yiisoft/yii2": "22.0.x-dev"
30+
"predis/predis": "^3.0"
3031
},
3132
"require-dev": {
32-
"phpunit/phpunit": "^9.6"
33+
"phpunit/phpunit": "9.*"
3334
},
3435
"autoload": {
3536
"psr-4": { "yii\\redis\\": "src" }

docs/guide-ja/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Yii 2 Redis キャッシュ、セッションおよびアクティブレコー
99
--------
1010

1111
* [インストール](installation.md)
12+
* [Predisサポート](predis.md)
1213

1314
使用方法
1415
--------

docs/guide-ja/predis.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
Yii 2 Redis キャッシュ、セッションおよびアクティブレコード Predis
2+
===============================================
3+
## アプリケーションを構成する
4+
5+
このエクステンションを使用するためには、アプリケーション構成情報で [[yii\redis\predis\PredisConnection]] クラスを構成する必要があります。
6+
7+
> Warning: yii\redis\predis\PredisConnection クラスは redis-cluster 接続をサポートしますが、*cache**session**ActiveRecord**mutex* コンポーネント インタフェースのサポートは提供しません。
8+
9+
### standalone
10+
```php
11+
return [
12+
//....
13+
'components' => [
14+
'redis' => [
15+
'class' => 'yii\redis\predis\PredisConnection',
16+
'parameters' => 'tcp://redis:6379',
17+
'options' => [
18+
'parameters' => [
19+
'password' => 'secret', // Or NULL
20+
'database' => 0,
21+
'persistent' => true,
22+
'async_connect' => true,
23+
'read_write_timeout' => 0.1,
24+
],
25+
],
26+
],
27+
]
28+
];
29+
```
30+
### sentinel
31+
```php
32+
return [
33+
//....
34+
'components' => [
35+
'redis' => [
36+
'class' => 'yii\redis\predis\PredisConnection',
37+
'parameters' => [
38+
'tcp://redis-node-1:26379',
39+
'tcp://redis-node-2:26379',
40+
'tcp://redis-node-3:26379',
41+
],
42+
'options' => [
43+
'parameters' => [
44+
'password' => 'secret', // Or NULL
45+
'database' => 0,
46+
'persistent' => true,
47+
'async_connect' => true,
48+
'read_write_timeout' => 0.1,
49+
],
50+
],
51+
],
52+
]
53+
];
54+
```
55+
56+
> 接続構成とオプションの詳細については、<a href="https://github.com/predis/predis">predis</a> のドキュメントを参照してください。
57+
58+
これで、`redis` アプリケーション・コンポーネントによって、redis ストレージに対する基本的なアクセスが提供されるようになります。
59+
60+
```php
61+
Yii::$app->redis->set('mykey', 'some value');
62+
echo Yii::$app->redis->get('mykey');
63+
```
64+
65+
追加のトピック
66+
-----------------
67+
68+
* [predisでキャッシュコンポーネントを使用する](topics-predis-cache.md)
69+
* [Predisでセッションコンポーネントを使用する](topics-predis-session.md)
70+

docs/guide-ja/topics-cache.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ return [
3737
```
3838

3939
このキャッシュは [[yii\caching\CacheInterface]] の全てのメソッドを提供します。インタフェイスに含まれていない redis 固有のメソッドにアクセスしたい場合は、
40-
[[yii\redis\Connection]] のインスタンスである [[yii\redis\Cache::$redis]] を通じてアクセスすることが出来ます。
40+
[[yii\redis\ConnectionInterface]] のインスタンスである [[yii\redis\Cache::$redis]] を通じてアクセスすることが出来ます。
4141

4242
```php
4343
Yii::$app->cache->redis->hset('mykey', 'somefield', 'somevalue');
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
キャッシュ・コンポーネントを使用する Predis
2+
=========================
3+
4+
`Cache` コンポーネントを使用するためには、[predis](predis.md) の節で説明した接続の構成に加えて、
5+
`cache` コンポーネントを [[yii\redis\Cache]] として構成する必要があります。
6+
7+
```php
8+
return [
9+
//....
10+
'components' => [
11+
// ...
12+
'redis' => [
13+
'class' => 'yii\redis\predis\PredisConnection',
14+
'parameters' => 'tcp://redis:6379',
15+
// ...
16+
],
17+
'cache' => [
18+
'class' => 'yii\redis\Cache',
19+
],
20+
]
21+
];
22+
```
23+
24+
redis をキャッシュとしてのみ使用する場合、すなわち、redis のアクティブレコードやセッションを使用しない場合は、接続のパラメータをキャッシュ・コンポーネントの中で構成しても構いません
25+
(この場合、接続のアプリケーション・コンポーネントを構成する必要はありません)。
26+
27+
```php
28+
return [
29+
//....
30+
'components' => [
31+
// ...
32+
'cache' => [
33+
'class' => 'yii\redis\Cache',
34+
'redis' => [
35+
'class' => 'yii\redis\predis\PredisConnection',
36+
'parameters' => 'tcp://redis:6379',
37+
// ...
38+
],
39+
],
40+
]
41+
];
42+
```
43+
44+
このキャッシュは [[yii\caching\CacheInterface]] の全てのメソッドを提供します。インタフェイスに含まれていない redis 固有のメソッドにアクセスしたい場合は、
45+
[[yii\redis\ConnectionInterface]] のインスタンスである [[yii\redis\Cache::$redis]] を通じてアクセスすることが出来ます。
46+
47+
```php
48+
Yii::$app->cache->redis->hset('mykey', 'somefield', 'somevalue');
49+
Yii::$app->cache->redis->hget('mykey', 'somefield');
50+
...
51+
```
52+
53+
利用可能なメソッドの一覧は [[yii\redis\predis\PredisConnection]] を参照して下さい。
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
セッション・コンポーネントを使用する Predis
2+
===========================
3+
4+
`Session` コンポーネントを使用するためには、[predis](predis.md) の節で説明した接続の構成に加えて、
5+
`session` コンポーネントを [[yii\redis\Session]] として構成する必要があります。
6+
7+
```php
8+
return [
9+
//....
10+
'components' => [
11+
// ...
12+
'redis' => [
13+
'class' => 'yii\redis\predis\PredisConnection',
14+
'parameters' => 'tcp://redis:6379',
15+
// ...
16+
],
17+
'session' => [
18+
'class' => 'yii\redis\Session',
19+
],
20+
]
21+
];
22+
```
23+
24+
redis をセッションとしてのみ使用する場合、すなわち、redis のアクティブレコードやキャッシュは使わない場合は、接続のパラメータをセッション・コンポーネントの中で構成しても構いません
25+
(この場合、接続のアプリケーション・コンポーネントを構成する必要はありません)。
26+
27+
```php
28+
return [
29+
//....
30+
'components' => [
31+
// ...
32+
'session' => [
33+
'class' => 'yii\redis\Session',
34+
'redis' => [
35+
'class' => 'yii\redis\predis\PredisConnection',
36+
'parameters' => 'tcp://redis:6379',
37+
// ...
38+
],
39+
],
40+
]
41+
];
42+
```

0 commit comments

Comments
 (0)