说白了,yiiredis中的AR功能的model其实就是一个hash,只是稍作封装了而已
官方有例子:
Using Redis as a backend for Active Record
It is possible to store active record like structures in redis using ARedisRecord.
Note: this is experimental functionality and may be subject to change
$record = ARedisRecord::model()->findByPk(1); // loads a record with a unique id of 1 $record->name = "a test name"; // sets the name attribute on the record $record->somethingElse = "some other value"; $record->save(); // saves the record to redis $record->delete(); // deletes the record from redis
不过,上面的例子不能直接拿来用,因为ARedisRecord是一个abstract类,所以你得写一个类继承于他才行。
顺便,如果用setAttributes的时候,记得加第二个参数(除非你写了rules),否则一定要加第二个参数,不然save不成功哦。
昨天被它折腾了好久才发现
----
笔记而已