1. Go to this page and download the library: Download alvin0/redis-model library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
alvin0 / redis-model example snippets
use Alvin0\RedisModel\Model;
class User extends Model {
/**
* The model's sub keys for the model.
*
* @var array
*/
protected $subKeys = [
'name',
'role',
];
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
protected $fillable = [
'id',
'email',
'name',
'role',
'address'
];
}
use Alvin0\RedisModel\Model;
class User extends Model {
/**
* The primary key for the model.
*
* @var bool
*/
protected $primaryKey = 'email';
/**
* Indicates if the IDs are auto-incrementing.
*
* @var bool
*/
public $incrementing = false;
/**
* The model's sub keys for the model.
*
* @var array
*/
protected $subKeys = [
'name',
'role',
];
/**
* The attributes that are mass assignable.
*
* @var array<string>
*/
protected $fillable = [
'email',
'name',
'role',
'address'
];
}
use Alvin0\RedisModel\Model;
class User extends Model {
// ...
}
use Alvin0\RedisModel\Model;
class User extends Model {
/**
* The model's table.
*
* @var array
*/
protected $table = "";
/**
* The model's prefixTable.
*
* @var array
*/
protected $prefixTable = null;
}
use Alvin0\RedisModel\Model;
class User extends Model {
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;
}
use Alvin0\RedisModel\Model;
class User extends Model {
/**
* @var string|null
*/
protected $connectionName = null;
}
use App\RedisModels\User;
User::where('email', '[email protected]')
->where('role', 'admin')
->get();
use App\RedisModels\User;
User::where('name', "user_*")->get();
use App\RedisModels\User;
use Alvin0\RedisModel\Collection;
User::where('user_id', 1)
->chunk(10, function (Collection $items) {
foreach ($items as $item) {
dump($item);
}
});
use App\RedisModels\User;
// Retrieve a model by its primary key...
$user = User::find('value_primary_key');
// Retrieve the first model matching the query constraints...
$user = User::where('email', '[email protected]')->first();
use App\RedisModels\User;
$user = new User;
$user->email = '[email protected]';
$user->name = 'Alvin0';
$user->token = '8f8e847890354d23b9a762f4d2612ce5';
$user->token = now();
$user->save()
use Alvin0\RedisModel\Model;
class User extends Model {
/**
* Indicates when generating but key exists
*
* @var bool
*/
protected $preventCreateForce = true;
}