redis->getClient()->hgetall($key); } catch (Exception $e) { throw new CException(Yii::t('model', $e->getMessage())); } } /** * set * * @param mixed $data * @return void * @param $time 在redis里的有效时间 */ public static function set($key, $data, $time = 86400) { try { $return = Yii::app()->redis->getClient()->hmset($key, $data); if($time != null){ return Yii::app()->redis->getClient()->expire($key, $time); }else{ return $return; } } catch (Exception $e) { throw new CException(Yii::t('model', $e->getMessage())); } } /** * remove * hDel每次只能删除单个Key, * 所以此处需要一个循环来逐个删除字段 * * @param mixed $key * @return void */ public static function remove($key) { try { $keys = Yii::app()->redis->getClient()->hkeys($key); foreach ($keys as $k) { Yii::app()->redis->getClient()->hdel($key, $k); } return true; } catch (Exception $e) { throw new CException(Yii::t('model', $e->getMessage())); } } }