insolita/yii2-arsync

This behavior for automatic or manual sync data between two models, without declaration relation. This behavior must be attached on master model. Main purposes - for sync rarely modified data from more reliable database storage to redis storage for frequently access; Support actual data state in so

Maintainers

👁 Insolita

Package info

github.com/Insolita/yii2-arsync

Type:yii2-extension

pkg:composer/insolita/yii2-arsync

Statistics

Installs: 30

Dependents: 0

Suggesters: 0

Stars: 1

Open Issues: 0

0.0.1 2016-05-12 16:02 UTC

Requires

Requires (Dev)

None

Suggests

None

Provides

None

Conflicts

None

Replaces

None

MIT e090bc52032387effd97eb0e4e8350bb078ee33f

  • insolita <webmaster100500.woop@ya.ru>

extensionyii2 redis activerecord synchronization sync

This package is auto-updated.

Last update: 2026-06-11 20:20:21 UTC


README

This behavior for automatic or manual sync data between two models, without declaration relation. This behavior must be attached on master model. Main purposes - for sync rarely modified data from more reliable database storage to redis storage for frequently access; Support actual data state in some development cases;

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist insolita/yii2-arsync "*"

or add

"insolita/yii2-arsync": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by : See more in code

public function behaviors(){
 return [
 'ArSyncBehavior'=>[
 				'class' => ArSyncBehavior::class,
 				'slaveModel' => \your\model\namespase\Slave::className(),
 				'slaveScenario'=>'sync',
 				'errorSaveCallback'=>function($slave){
 Yii::error(VarDumper::export($slave->errors));
 throw new InvalidConfigException('fail save ');
 },
 'errorDeleteCallback'=>function($slave){
 Yii::error('fail delete '.$slave->getPrimaryKey());
 },
 				'fieldMap' => [
 					'id'=>'id',
 					'title' => 'name',
 					'foo' => 'foo',
 					'bar' => 'bar',
 					'baz' => function($master)
 					{
 						return $master->baz * 2;
 					},
 				],
 			]
 ];
}