我从Laravel Predis和Redis开始。问题是,在Laravel和Redis中一起处理更新的最佳方法是什么?这是最好的方法还是不能更简单?
雄辩更新:
$article = Article::find(1);
$article->title = Input::get('title');
$article->save();
Redis Hmset:
$client = Redis::connection();
$client->hmset('testtest', ['1'=> 'testtest']);
答案 0 :(得分:1)
在laravel,创建一个模型是必须的,这是一个样本模型:
class Article extends Model
{
// set your table name from your database
protected $table = 'articles';
// set each field at table
protected $fillable = [ 'title', 'content', 'status' ];
}
更新:
$article = Article::find(1);
$article->update( [
'title' => Input::get( 'title' ),
'content' => Input::get( 'content' ),
'status' => Input::get( 'status' ),
] );
在有更新时自动更新:
protected static function boot() {
parent::boot();
static::updated( function( $article ) {
$client = Redis::connection();
$client->hmset('testtest', ['1'=> 'testtest']);
});
}