Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
962252d
Merge commit from fork
samdark Jun 5, 2025
d5b89cb
release version 2.0.20
samdark Jun 5, 2025
0a90a54
prepare for next release
samdark Jun 5, 2025
bce389e
update tests
antonshevelev Jun 27, 2025
cb795ed
predis conn
antonshevelev Jun 27, 2025
5dfa1cf
predis standalone and sentinel
antonshevelev Jul 1, 2025
721fad7
ConnectionInterface
antonshevelev Jul 1, 2025
ddd8467
ConnectionInterface
antonshevelev Jul 1, 2025
9d8d059
fix test
antonshevelev Jul 2, 2025
6a1e916
PredisConnection
antonshevelev Jul 2, 2025
a16bbf6
predis on supported replicas
antonshevelev Jul 2, 2025
c48ee8a
code style
antonshevelev Jul 2, 2025
e5f0a66
del
antonshevelev Jul 2, 2025
8d709a3
comments
antonshevelev Jul 2, 2025
a7dcd7d
docs
antonshevelev Jul 2, 2025
5f4fef3
build
antonshevelev Jul 2, 2025
8f2a33b
build
antonshevelev Jul 2, 2025
fbadba2
build
antonshevelev Jul 2, 2025
8a389fc
build
antonshevelev Jul 2, 2025
3296606
build
antonshevelev Jul 2, 2025
631ef1b
build
antonshevelev Jul 2, 2025
f635042
build
antonshevelev Jul 2, 2025
abe55a7
build
antonshevelev Jul 2, 2025
285e192
build
antonshevelev Jul 2, 2025
351fa25
build
antonshevelev Jul 2, 2025
3f489e3
build
antonshevelev Jul 2, 2025
73a2312
fix test
antonshevelev Jul 2, 2025
f8d0a92
fix test
antonshevelev Jul 2, 2025
9cc9efb
remove test
antonshevelev Jul 2, 2025
76fcc88
fix test
antonshevelev Jul 2, 2025
9a318ee
returned and fix testConnectionTimeout
antonshevelev Jul 2, 2025
c002b14
comment
antonshevelev Jul 3, 2025
a192ce2
fix
antonshevelev Jul 3, 2025
04d54d2
Merge branch '22' into yii2-predis
antonshevelev Jul 3, 2025
5d0e4a1
fix tests
antonshevelev Jul 3, 2025
582264e
Update docs/guide-ja/README.md
antonshevelev Jul 8, 2025
649c010
Update docs/guide-ru/topics-predis-cache.md
antonshevelev Jul 8, 2025
952d60a
Update docs/guide-ru/topics-predis-session.md
antonshevelev Jul 8, 2025
aa6743b
Update docs/guide-ru/predis.md
antonshevelev Jul 8, 2025
faf8173
Update docs/guide/README.md
antonshevelev Jul 8, 2025
8407d90
translation of guide
antonshevelev Jul 8, 2025
9fb3962
upd guide
antonshevelev Jul 8, 2025
3b22ac8
remove php.ini
antonshevelev Jul 8, 2025
0745170
upd tests
antonshevelev Jul 8, 2025
4f4a01a
upd CommandDecorator
antonshevelev Jul 8, 2025
eb4e18a
upd
antonshevelev Jul 8, 2025
c0ed9d9
upd readme
antonshevelev Jul 8, 2025
c9a1ed3
upd changelog
antonshevelev Jul 8, 2025
80646e1
fix test
antonshevelev Jul 8, 2025
6070b6d
Update docs/guide/predis.md
samdark Jul 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 9 additions & 42 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,49 +31,16 @@ jobs:
- ubuntu-latest

php:
- 8.1
- 8.2
- 8.3
- 8.4

redis:
- 6
- 7
- 8

services:
redis:
image: redis:${{ matrix.redis }}
ports:
- 6379:6379
options: --health-cmd="redis-cli ping" --health-interval=10s --health-timeout=5s --health-retries=5
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install PHP with extensions
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, intl, redis
ini-values: date.timezone='UTC'
tools: composer:v2, pecl

- name: Install dependencies with Composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Run tests with phpunit.
if: matrix.php != '8.1'
run: vendor/bin/phpunit --colors=always

- name: Run tests with phpunit and generate coverage.
if: matrix.php == '8.1'
run: vendor/bin/phpunit --coverage-clover=coverage.xml --colors=always
uses: actions/checkout@v2

- name: Upload coverage to Codecov.
if: matrix.php == '8.1'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage.xml
- name: PHP tests for PHP ${{ matrix.php }}
run: |
ls -al
make test-sentinel v=${{ matrix.php }}
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
Yii Framework 2 redis extension Change Log
==========================================

2.0.20 under development
2.0.21 under development
------------------------

- New #276: Added support for predis (antonshevelev)
- New #276: Changed default value of yii\redis\Cache::$forceClusterMode to false (antonshevelev)
- New #276: Implemented yii\redis\ConnectionInterface in yii\redis\Connection (antonshevelev)
- New #276: Updated minimum required PHP version to 8.1 (antonshevelev)


2.0.20 June 05, 2025
--------------------

- Bug CVE-2025-48493: Prevent logging `AUTH` parameters when `YII_DEBUG` is off (samdark)
- Bug #270: Prevent null parameter on `mb_strlen` to avoid PHP 8.4 implicity nullable types deprecation (tehmaestro)


Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,15 @@ clean:
docker rm $(shell cat tests/dockerids/redis)
rm tests/dockerids/redis

test-sentinel:
make build
PHP_VERSION=$(filter-out $@,$(MAKECMDGOALS)) docker compose -f tests/docker/docker-compose.yml build --pull yii2-redis-php
PHP_VERSION=$(filter-out $@,$(MAKECMDGOALS)) docker compose -f tests/docker/docker-compose.yml up -d
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"

build: ## Build an image from a docker-compose file. Params: {{ v=8.1 }}. Default latest PHP 8.1
PHP_VERSION=$(filter-out $@,$(v)) docker compose -f tests/docker/docker-compose.yml up -d --build

down: ## Stop and remove containers, networks
docker compose -f tests/docker/docker-compose.yml down

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,8 @@ return [
]
];
```

Additional topics
-----------------

* [predis support](predis.md)
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@
],
"require": {
"php": ">=8.1",
"yiisoft/yii2": "22.0.x-dev",
"ext-openssl": "*",
"yiisoft/yii2": "22.0.x-dev"
"predis/predis": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^9.6"
"phpunit/phpunit": "9.*"
},
"autoload": {
"psr-4": { "yii\\redis\\": "src" }
Expand Down
1 change: 1 addition & 0 deletions docs/guide-ja/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Yii 2 Redis キャッシュ、セッションおよびアクティブレコー
--------

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

使用方法
--------
Expand Down
70 changes: 70 additions & 0 deletions docs/guide-ja/predis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Yii 2 Redis キャッシュ、セッションおよびアクティブレコード Predis
===============================================
## アプリケーションを構成する

このエクステンションを使用するためには、アプリケーション構成情報で [[yii\redis\predis\PredisConnection]] クラスを構成する必要があります。

> Warning: yii\redis\predis\PredisConnection クラスは redis-cluster 接続をサポートしますが、*cache*、*session*、*ActiveRecord*、*mutex* コンポーネント インタフェースのサポートは提供しません。

### standalone
```php
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => 'tcp://redis:6379',
'options' => [
'parameters' => [
'password' => 'secret', // Or NULL
'database' => 0,
'persistent' => true,
'async_connect' => true,
'read_write_timeout' => 0.1,
],
],
],
]
];
```
### sentinel
```php
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => [
'tcp://redis-node-1:26379',
'tcp://redis-node-2:26379',
'tcp://redis-node-3:26379',
],
'options' => [
'parameters' => [
'password' => 'secret', // Or NULL
'database' => 0,
'persistent' => true,
'async_connect' => true,
'read_write_timeout' => 0.1,
],
],
],
]
];
```

> 接続構成とオプションの詳細については、<a href="https://github.com/predis/predis">predis</a> のドキュメントを参照してください。

これで、`redis` アプリケーション・コンポーネントによって、redis ストレージに対する基本的なアクセスが提供されるようになります。

```php
Yii::$app->redis->set('mykey', 'some value');
echo Yii::$app->redis->get('mykey');
```

追加のトピック
-----------------

* [predisでキャッシュコンポーネントを使用する](topics-predis-cache.md)
* [Predisでセッションコンポーネントを使用する](topics-predis-session.md)

2 changes: 1 addition & 1 deletion docs/guide-ja/topics-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ return [
```

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

```php
Yii::$app->cache->redis->hset('mykey', 'somefield', 'somevalue');
Expand Down
53 changes: 53 additions & 0 deletions docs/guide-ja/topics-predis-cache.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
キャッシュ・コンポーネントを使用する Predis
=========================

`Cache` コンポーネントを使用するためには、[predis](predis.md) の節で説明した接続の構成に加えて、
`cache` コンポーネントを [[yii\redis\Cache]] として構成する必要があります。

```php
return [
//....
'components' => [
// ...
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => 'tcp://redis:6379',
// ...
],
'cache' => [
'class' => 'yii\redis\Cache',
],
]
];
```

redis をキャッシュとしてのみ使用する場合、すなわち、redis のアクティブレコードやセッションを使用しない場合は、接続のパラメータをキャッシュ・コンポーネントの中で構成しても構いません
(この場合、接続のアプリケーション・コンポーネントを構成する必要はありません)。

```php
return [
//....
'components' => [
// ...
'cache' => [
'class' => 'yii\redis\Cache',
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => 'tcp://redis:6379',
// ...
],
],
]
];
```

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

```php
Yii::$app->cache->redis->hset('mykey', 'somefield', 'somevalue');
Yii::$app->cache->redis->hget('mykey', 'somefield');
...
```

利用可能なメソッドの一覧は [[yii\redis\predis\PredisConnection]] を参照して下さい。
42 changes: 42 additions & 0 deletions docs/guide-ja/topics-predis-session.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
セッション・コンポーネントを使用する Predis
===========================

`Session` コンポーネントを使用するためには、[predis](predis.md) の節で説明した接続の構成に加えて、
`session` コンポーネントを [[yii\redis\Session]] として構成する必要があります。

```php
return [
//....
'components' => [
// ...
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => 'tcp://redis:6379',
// ...
],
'session' => [
'class' => 'yii\redis\Session',
],
]
];
```

redis をセッションとしてのみ使用する場合、すなわち、redis のアクティブレコードやキャッシュは使わない場合は、接続のパラメータをセッション・コンポーネントの中で構成しても構いません
(この場合、接続のアプリケーション・コンポーネントを構成する必要はありません)。

```php
return [
//....
'components' => [
// ...
'session' => [
'class' => 'yii\redis\Session',
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => 'tcp://redis:6379',
// ...
],
],
]
];
```
1 change: 1 addition & 0 deletions docs/guide-pt-BR/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Iniciando
---------------

* [Instalação](installation.md)
* [Suporte predis](predis.md)

Uso
-----
Expand Down
70 changes: 70 additions & 0 deletions docs/guide-pt-BR/predis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
Predis para Redis Cache, Sessão e ActiveRecord para Yii 2
===============================================
## Configurando a aplicação

Para usar essa extensão, você precisa parametrizar a classe [[yii\redis\predis\PredisConnection]] na configuração da aplicação:

> Warning: A classe yii\redis\predis\PredisConnection suporta conexão redis-cluster, mas não fornece suporte para as interfaces de componentes *cache*, *session*, *ActiveRecord*, *mutex*.

### standalone
```php
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => 'tcp://redis:6379',
'options' => [
'parameters' => [
'password' => 'secret', // Or NULL
'database' => 0,
'persistent' => true,
'async_connect' => true,
'read_write_timeout' => 0.1,
],
],
],
]
];
```
### sentinel
```php
return [
//....
'components' => [
'redis' => [
'class' => 'yii\redis\predis\PredisConnection',
'parameters' => [
'tcp://redis-node-1:26379',
'tcp://redis-node-2:26379',
'tcp://redis-node-3:26379',
],
'options' => [
'parameters' => [
'password' => 'secret', // Or NULL
'database' => 0,
'persistent' => true,
'async_connect' => true,
'read_write_timeout' => 0.1,
],
],
],
]
];
```

> Mais informações sobre configuração e opções de conexão podem ser encontradas na documentação do <a href="https://github.com/predis/predis">predis</a>.

Isto fornece o acesso básico ao armazenamento de redis através do componente de aplicação `redis`:

```php
Yii::$app->redis->set('mykey', 'some value');
echo Yii::$app->redis->get('mykey');
```

Additional topics
-----------------

* [Usando o componente Cache com predis](topics-predis-cache.md)
* [Usando o componente Session com predis](topics-predis-session.md)

2 changes: 1 addition & 1 deletion docs/guide-pt-BR/topics-cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ return [
];
```

O cache fornece todos os métodos do [[yii\caching\CacheInterface]]. Se você quiser acessar os métodos específicos do redis que não são incluído na interface, você pode usá-los via [[yii\redis\Cache::$redis]], que é uma instância de [[yii\redis\Connection]]:
O cache fornece todos os métodos do [[yii\caching\CacheInterface]]. Se você quiser acessar os métodos específicos do redis que não são incluído na interface, você pode usá-los via [[yii\redis\Cache::$redis]], que é uma instância de [[yii\redis\ConnectionInterface]]:

```php
Yii::$app->cache->redis->hset('mykey', 'somefield', 'somevalue');
Expand Down
Loading
Loading