① memcached可以持久化嗎
memcached 是緩存系統,通過名字就可以看出來,官網也明確說了(Free & open source, high-performance, distributed memory object caching system),之所以是緩存系統,就說明它不會作為可靠的數據存儲,所以並不支持持久化。
另一個是redis,他是一個存儲系統,官網也說了。只不過redis是在內存中存儲的,所以速度快,因為是存儲系統,所以可以作為一個可靠的數據存儲系統。支持持久化。
② 如何改變memcached默認的緩存時間
至於設置一個UNIX時間戳或 以秒為單位的整數(從當前算起的時間差)來說明此數據的過期時間,但是在後一種設置方式中,不能超過 2592000秒(30天)的問題我們該怎麼辦呢?我們不想設置為永久有效,但是也不想再限制在30天內。那麼方法來了,這里就以官方文檔的代碼為示例代碼,如下。
<?php
$memcache_obj = memcache_connect(「localhost」, 11211);
/* 面向過程編程 API */
memcache_add($memcache_obj, 'var_key', 'test variable', false, 0);// 永久有效
/* 面向對象編程 API */
$memcache_obj->add(『var_key', 'test variable', false, time()+24*60*60*30);// 超過30天
?>
③ ThinkPHP5.0怎麼使用memcache
在配置文件配置
'cache'=>[
//驅動方式
'type'=>'memcache',
//緩存保存目錄
'path'=>CACHE_PATH,
//緩存前綴
'prefix'=>'',
//緩存有效期0表示永久緩存
'expire'=>0,
],
④ 在MemCache中設置有效時間expiry,是怎樣設置的
30在MemCache中設置有
⑤ 如何為sae memcache設置有效期
1、下載並安裝memcache (1)window下安裝memcache. 下載memcached.exe 到d:/memcached/memcached.exe.在運行cmd 輸入 d:/memcached/memcached.exe -d install安裝 。 (2)運行d:/memcached/memcached.exe -d start 啟動memcache
⑥ 如何查找memcache中過期的數據
如何遍歷memcache
stats命令
memcache的stats命令包括:
1. stats
2. stats reset
3. stats malloc
4. stats maps
5. stats sizes
6. stats slabs
7. stats items
8. stats cachemp slab_id limit_num
9. stats detail [on|off|mp]
通過命令完成遍歷
通過這些stats命令我們就可以完成memcache存儲的內容的遍歷,OK,下面我們通過telnet直接連接到memcache通過這些命令來完成相關的操作。
telnet到192.168.15.225(區域網測試機器)的memcache伺服器
執行stats items命令,可以看到出現 很多的items行。
執行stats cachemp 3 0命令。這里的3表示上面圖中items後面的數字,0標示顯示全部的數據,如果是1就標示只顯示1條。
下圖為執行後的結果,item後面的字元串為key
通過上面列出的key我們就可以遍歷所有的數據了,下面我們取出某一條數據,key為Uc!uLh的數據。
到這里,你也許明白了怎麼去遍歷memcache的數據了。
求採納~~~~
⑦ PHP可以拿到memcache中的key的過期時間嗎
memcached 數據過期機制 lazy expiration
內部不會監視記錄是否過期,而是在get時查看記錄的時間戳,檢查記錄是否過期。這種技術被稱為lazy(惰性)expiration。因此,memcached不會在過期監視上耗費CPU時間,換句話說,也不能 檢測 某個key的過期時間。
可以使用一種較笨的方法:
definde('MEM_TIME_OUT',1800);
$memKey = "testkey";
$val = 'This is test value';
mem_set($key,$val); //調用
function mem_set($key,$val) {
$memcache -> set($memKey,$val, 0, MEM_TIME_OUT);
//當調用set 的時候順便加一條記錄時間
$memcache -> set('TIME_'.$memKey,time(), 0, MEM_TIME_OUT);
}
function mem_get($key,$is_time = false) {
$memKey = $is_time ? 'TIME_'.$key : $key;
$val = $memcache -> get($key);
if($is_time) {
$val = MEM_TIME_OUT - (time() - $val);
}
return $val;
}
⑧ memcache 必須要設置flushinterval嗎
Memcache類摘要
Memcache {
bool add ( string $key , mixed $var [, int $flag [, int $expire ]] )
bool addServer ( string $host [, int $port = 11211 [, bool $persistent [, int $weight [, int $timeout [, int $retry_interval [, bool $status [, callback $failure_callback [, int $timeoutms ]]]]]]]] )
bool close ( void )
bool connect ( string $host [, int $port [, int $timeout ]] )
int decrement ( string $key [, int $value = 1 ] )
bool delete ( string $key [, int $timeout ] )
bool flush ( void )
string get ( string $key [, int &$flags ] )
array getExtendedStats ([ string $type [, int $slabid [, int $limit = 100 ]]] )
int getServerStatus ( string $host [, int $port = 11211 ] )
array getStats ([ string $type [, int $slabid [, int $limit = 100 ]]] )
string getVersion ( void )
int increment ( string $key [, int $value = 1 ] )
bool pconnect ( string $host [, int $port [, int $timeout ]] )
bool replace ( string $key , mixed $var [, int $flag [, int $expire ]] )
bool set ( string $key , mixed $var [, int $flag [, int $expire ]] )
bool setCompressThreshold ( int $threshold [, float $min_savings ] )
bool setServerParams ( string $host [, int $port = 11211 [, int $timeout [, int $retry_interval = false [, bool $status [, callback $failure_callback ]]]]] )
}
Table of Contents
■Memcache::add — 增加一個條目到緩存伺服器
■Memcache::addServer — 向連接池中添加一個memcache伺服器
■Memcache::close — 關閉memcache連接
■Memcache::connect — 打開一個memcached服務端連接
■Memcache::decrement — 減小元素的值
■Memcache::delete — 從服務端刪除一個元素
■Memcache::flush — 清洗(刪除)已經存儲的所有的元素
■Memcache::get — 從服務端檢回一個元素
■Memcache::getExtendedStats — 緩存伺服器池中所有伺服器統計信息
■Memcache::getServerStatus — 用於獲取一個伺服器的在線/離線狀態
■Memcache::getStats — 獲取伺服器統計信息
■Memcache::getVersion — 返回伺服器版本信息
■Memcache::increment — 增加一個元素的值
■Memcache::pconnect — 打開一個到伺服器的持久化連接
■Memcache::replace — 替換已經存在的元素的值
■Memcache::set — Store data at the server
■Memcache::setCompressThreshold — 開啟大值自動壓縮
■Memcache::setServerParams — 運行時修改伺服器參數和狀態
Memcache::add用法
bool Memcache::add ( string $key , mixed $var [, int $flag [, int $expire ]] )
⑨ memchache的默認過期時間是多少,我不設這個時間會多少長時間到期呢
不設置,默認永久保存。除非memchache進程退出或掉電。
⑩ PHP可以拿到memcache中的key的過期時間嗎
memcached 數據過期機制 lazy expiration
內部不會監視記錄是否過期,而是在get時查看記錄的時間戳,檢查記錄是否過期。這種技術被稱為lazy(惰性)expiration。因此,memcached不會在過期監視上耗費CPU時間,換句話說,也不能 檢測 某個key的過期時間。。
可以使用一種較笨的方法:
definde('MEM_TIME_OUT',1800);
$memKey = "testkey";
$val = 'This is test value';
mem_set($key,$val); //調用
function mem_set($key,$val) {
$memcache -> set($memKey,$val, 0, MEM_TIME_OUT);
//當調用set 的時候順便加一條記錄時間
$memcache -> set('TIME_'.$memKey,time(), 0, MEM_TIME_OUT);
}
function mem_get($key,$is_time = false) {
$memKey = $is_time ? 'TIME_'.$key : $key;
$val = $memcache -> get($key);
if($is_time) {
$val = MEM_TIME_OUT - (time() - $val);
}
return $val;
}
大概意思就是這樣。。 期待高手給出更完美,簡單的方法。。