Skip to content

Commit efe038d

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
1 parent 0a90a54 commit efe038d

File tree

87 files changed

+7701
-414
lines changed

Some content is hidden

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

87 files changed

+7701
-414
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,48 @@
11
on:
2-
- pull_request
3-
- push
2+
pull_request:
3+
paths-ignore:
4+
- 'docs/**'
5+
- 'README.md'
6+
- 'CHANGELOG.md'
7+
- '.gitignore'
8+
- '.gitattributes'
9+
10+
push:
11+
paths-ignore:
12+
- 'docs/**'
13+
- 'README.md'
14+
- 'CHANGELOG.md'
15+
- '.gitignore'
16+
- '.gitattributes'
417

518
name: build
619

720
jobs:
821
tests:
9-
name: PHP ${{ matrix.php }}-redis-4
22+
name: PHP ${{ matrix.php }}-redis-${{ matrix.redis }}
1023

1124
runs-on: ${{ matrix.os }}
1225

1326
strategy:
27+
fail-fast: false
28+
1429
matrix:
1530
os:
1631
- ubuntu-latest
1732

1833
php:
19-
- "5.4"
20-
- "5.5"
21-
- "5.6"
22-
- "7.0"
23-
- "7.1"
24-
- "7.2"
2534
- "7.3"
2635
- "7.4"
36+
- "8.0"
37+
- "8.1"
38+
- "8.2"
39+
- "8.3"
40+
- "8.4"
2741

2842
steps:
2943
- name: Checkout
3044
uses: actions/checkout@v2
3145

32-
- name: Start Redis v4
33-
uses: superchargejs/[email protected]
34-
with:
35-
redis-version: 4
36-
37-
- name: Install PHP with extensions
38-
uses: shivammathur/setup-php@v2
39-
with:
40-
php-version: ${{ matrix.php }}
41-
extensions: curl, intl, redis
42-
ini-values: date.timezone='UTC'
43-
tools: composer:v2, pecl
44-
45-
- name: Get Composer cache directory
46-
id: composer-cache
47-
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
48-
49-
- name: Cache Composer dependencies
50-
uses: actions/[email protected]
51-
with:
52-
path: ${{ steps.composer-cache.outputs.dir }}
53-
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
54-
restore-keys: ${{ runner.os }}-composer-
55-
56-
- name: Install dependencies with Composer
57-
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader
58-
59-
- name: Run Redis tests with PhpUnit
60-
run: vendor/bin/phpunit --coverage-clover=coverage.clover
46+
- name: PHP tests for PHP ${{ matrix.php }}
47+
run: |
48+
make test-sentinel v=${{ matrix.php }}

.github/workflows/ci-redis.yml

Lines changed: 0 additions & 69 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Yii Framework 2 redis extension Change Log
44
2.0.21 under development
55
------------------------
66

7-
- no changes in this release.
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)
810

911

1012
2.0.20 June 05, 2025

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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
2222
Requirements
2323
------------
2424

25-
At least redis version 2.6.12 is required for all components to work properly.
25+
At least redis version is required for all components to work properly.
2626

2727
Installation
2828
------------
@@ -100,3 +100,8 @@ return [
100100
]
101101
];
102102
```
103+
104+
Additional topics
105+
-----------------
106+
107+
* [predis support](/docs/guide/predis.md)

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
{
22
"name": "yiisoft/yii2-redis",
33
"description": "Redis Cache, Session and ActiveRecord for the Yii framework",
4+
"keywords": [
5+
"yii2",
6+
"redis",
7+
"active-record",
8+
"cache",
9+
"session"
10+
],
411
"keywords": ["yii2", "redis", "active-record", "cache", "session"],
512
"type": "yii2-extension",
613
"license": "BSD-3-Clause",
@@ -18,11 +25,13 @@
1825
}
1926
],
2027
"require": {
28+
"php": "^7.3 || ^8.0",
2129
"yiisoft/yii2": "~2.0.39",
22-
"ext-openssl": "*"
30+
"ext-openssl": "*",
31+
"predis/predis": "^v2.3.0|^3.0"
2332
},
2433
"require-dev": {
25-
"phpunit/phpunit": "<7",
34+
"phpunit/phpunit": "9.*",
2635
"yiisoft/yii2-dev": "~2.0.39"
2736
},
2837
"autoload": {

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]] を参照して下さい。

0 commit comments

Comments
 (0)