1
0
mirror of https://github.com/MoePlayer/APlayer-Typecho.git synced 2025-03-21 21:00:22 +08:00

⚙ Add PostgreSQL support

This commit is contained in:
weilinfox 2022-07-29 18:37:50 +08:00
parent 16fb10a134
commit b526c9171f
2 changed files with 55 additions and 2 deletions

View File

@ -105,7 +105,8 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
'redis' => _t('Redis'),
'memcached' => _t('Memcached'),
'mysql' => _t('MySQL'),
'sqlite' => _t('SQLite')
'sqlite' => _t('SQLite'),
'postgres' => _t('PostgreSQL')
);
$t = new Typecho_Widget_Helper_Form_Element_Radio(
'cachetype',
@ -128,7 +129,7 @@ class Meting_Plugin extends Typecho_Widget implements Typecho_Plugin_Interface
null,
'6379',
_t('缓存服务端口'),
_t('默认端口 memcache: 11211, Redis: 6379, Mysql: 3306')
_t('默认端口 memcache: 11211, Redis: 6379, Mysql: 3306, PostgreSQL: 5432')
);
$form->addInput($t);

52
driver/postgres.class.php Normal file
View File

@ -0,0 +1,52 @@
<?php
class MetingCache implements MetingCacheI
{
private $db = null;
public function __construct($option)
{
$this->db = Typecho_Db::get();
$dbname = $this->db->getPrefix() . 'metingcache';
$this->install();
$this->db->query($this->db->delete('table.metingcache')->where('time <= ?', time()));
}
public function install()
{
$sql = '
CREATE TABLE IF NOT EXISTS "' . $this->db->getPrefix() . 'metingcache' . '" (
"key" varchar(32) NOT NULL PRIMARY KEY,
"data" text,
"time" NUMERIC(20) DEFAULT NULL
);';
$this->db->query($sql);
}
public function set($key, $value, $expire = 86400)
{
$this->db->query($this->db->insert('table.metingcache')->rows(array(
'key' => md5($key),
'data' => $value,
'time' => time() + $expire
)));
}
public function get($key)
{
$rs = $this->db->fetchRow($this->db->select('data')->from('table.metingcache')->where('key = ?', md5($key)));
if (count($rs) == 0) {
return false;
} else {
return $rs['data'];
}
}
public function flush()
{
return $this->db->query($this->db->delete('table.metingcache'));
}
public function check()
{
$number = uniqid();
$this->set('check', $number, 60);
$cache = $this->get('check');
if ($number != $cache) {
throw new Exception('Cache Test Fall!');
}
}
}