Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
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
66 changes: 26 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,46 @@
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.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: |
ls -al
make test-sentinel v=${{ matrix.php }}
69 changes: 0 additions & 69 deletions .github/workflows/ci-redis.yml

This file was deleted.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ 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)
- New #276: Updated minimum required PHP version to 8.1 (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](predis.md)
18 changes: 13 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +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",
"support": {
Expand All @@ -18,12 +24,14 @@
}
],
"require": {
"yiisoft/yii2": "~2.0.39",
"ext-openssl": "*"
"php": ">=8.1",
"yiisoft/yii2": "~2.0.51",
"ext-openssl": "*",
"predis/predis": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "<7",
"yiisoft/yii2-dev": "~2.0.39"
"phpunit/phpunit": "9.*",
"yiisoft/yii2-dev": "~2.0.51"
},
"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]] を参照して下さい。
Loading