Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
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
2cc938a
support yii2
antonshevelev Jul 10, 2025
793bb9a
upd
antonshevelev Jul 10, 2025
ea2ce49
fix test
antonshevelev Jul 10, 2025
07d5e91
fix test
antonshevelev Jul 10, 2025
b9c9e69
support for older versions php
antonshevelev Jul 14, 2025
94da1f3
fix test
antonshevelev Jul 14, 2025
fccdc06
fix test
antonshevelev Jul 14, 2025
747b2c3
upd composer.json
antonshevelev Jul 14, 2025
b82e0d4
upd changelog
antonshevelev Jul 14, 2025
1da9308
upd
antonshevelev Jul 14, 2025
579f07b
upd
antonshevelev Jul 14, 2025
7ea62db
upd
antonshevelev Jul 14, 2025
3c81a0c
skip flaky tests
antonshevelev Jul 14, 2025
74572e1
markTestSkipped
antonshevelev Jul 14, 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
64 changes: 26 additions & 38 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,48 @@
on:
- pull_request
- push
pull_request:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'

push:
paths-ignore:
- 'docs/**'
- 'README.md'
- 'CHANGELOG.md'
- '.gitignore'
- '.gitattributes'

name: build

jobs:
tests:
name: PHP ${{ matrix.php }}-redis-4
name: PHP ${{ matrix.php }}-redis-${{ matrix.redis }}

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

strategy:
fail-fast: false

matrix:
os:
- ubuntu-latest

php:
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"

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

- name: Start Redis v4
uses: superchargejs/[email protected]
with:
redis-version: 4

- 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: Get Composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache Composer dependencies
uses: actions/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

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

- name: Run Redis tests with PhpUnit
run: vendor/bin/phpunit --coverage-clover=coverage.clover
- name: PHP tests for PHP ${{ matrix.php }}
run: |
make test-sentinel v=${{ matrix.php }}
69 changes: 0 additions & 69 deletions .github/workflows/ci-redis.yml

This file was deleted.

4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Yii Framework 2 redis extension Change Log
2.0.21 under development
------------------------

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


2.0.20 June 05, 2025
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

7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Documentation is at [docs/guide/README.md](docs/guide/README.md).
Requirements
------------

At least redis version 2.6.12 is required for all components to work properly.
At least redis version is required for all components to work properly.

Installation
------------
Expand Down Expand Up @@ -100,3 +100,8 @@ return [
]
];
```

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

* [predis support](/docs/guide/predis.md)
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
{
"name": "yiisoft/yii2-redis",
"description": "Redis Cache, Session and ActiveRecord for the Yii framework",
"keywords": [
"yii2",
"redis",
"active-record",
"cache",
"session"
],
"keywords": ["yii2", "redis", "active-record", "cache", "session"],
"type": "yii2-extension",
"license": "BSD-3-Clause",
Expand All @@ -18,11 +25,13 @@
}
],
"require": {
"php": "^7.3 || ^8.0",
"yiisoft/yii2": "~2.0.39",
"ext-openssl": "*"
"ext-openssl": "*",
"predis/predis": "^v2.3.0|^3.0"
},
"require-dev": {
"phpunit/phpunit": "<7",
"phpunit/phpunit": "9.*",
"yiisoft/yii2-dev": "~2.0.39"
},
"autoload": {
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]] を参照して下さい。
Loading