Redis implementation, #16

git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@149 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
pzinovkin
2010-07-19 15:06:01 +00:00
parent 70ccc8bc26
commit 8a6f6097bf
8 changed files with 185 additions and 195 deletions

View File

@ -34,7 +34,7 @@ class SessionModel extends Model
public function read($id)
{
$sql = 'SELECT `data` FROM ' . $this->table() . ' WHERE `id`=? AND `expires` > UNIX_TIMESTAMP()';
$sql = 'SELECT `data` FROM :table WHERE `id`=? AND `expires` > UNIX_TIMESTAMP()';
return (string) $this->fetchField($sql, $id, 'data');
}
@ -45,21 +45,23 @@ class SessionModel extends Model
$ip = Env::Server('HTTP_X_FORWARDED_FOR', Env::Server('REMOTE_ADDR'));
$sql = 'INSERT INTO ' . $this->table() . ' (`id`, `expires`, `ip`, `user_id`, `data`)'
. ' VALUES(' . $this->quote($id) . ', UNIX_TIMESTAMP() + ' . (int) $this->life_time . ', INET_ATON(' . $this->quote($ip) . '), ' . $user_id . ', ' . $this->quote($data) . ')'
. ' ON DUPLICATE KEY UPDATE `expires`=UNIX_TIMESTAMP() + ' . (int) $this->life_time . ', `ip`=INET_ATON(' . $this->quote($ip) . '), `user_id`=' . $user_id . ', `data`=' . $this->quote($data);
$affected = $this->db->query($sql)->affectedRows();
return (bool) ($this->getInsertId()) ? $this->getInsertId() : $affected;
$update = array(
'expires' => new DbExpr('UNIX_TIMESTAMP() + ' . (int) $this->life_time),
'ip' => new DbExpr('INET_ATON(' . $this->quote($ip) . ')'),
'user_id' => $user_id,
'data' => $data
);
return (bool) $this->insert(array('id' => $id) + $update, $update);
}
public function destroy($id)
{
return (bool) $this->db->delete($this->table(false), array('`id`=?' => (string) $id));
return (bool) $this->db->delete($this->table(), array('`id`=?' => (string) $id));
}
public function gc($max_life_time)
{
return (bool) $this->db->delete($this->table(false), '`expires` < UNIX_TIMESTAMP()');
return (bool) $this->db->delete($this->table(), '`expires` < UNIX_TIMESTAMP()');
}
/* End of Session handler methods */
@ -67,6 +69,6 @@ class SessionModel extends Model
public function destroyByUserId($user_id)
{
return $this->db->delete($this->table(false), array('`user_id`=?' => $user_id));
return $this->db->delete($this->table(), array('`user_id`=?' => $user_id));
}
}