memcachedb使用
2009-10-22 3:29 pm以前就听说过memcachedb了,但是一直也没有直接的使用上,最近项目中要用到,所以写点使用的总结,
1.介绍:
说这个肯定是废话,还是一句话说一下,使用memcache协议,分布能力来使用Berkeley db,也不知道这样准不准确。
1.安装:
官方中说的很清楚,摘录一下就可以,另外,如果ubuntu安装libenvent可以使用
apt-get install libevent1
其他的就需要编译安装了:
Berkeley DB 4.7 or later ------------------------- http://www.oracle.com/database/berkeley-db/db/index.html How to install BerkekeyDB: $tar xvzf db-4.7.25.tar.gz $cd db-4.7.25/ $cd build_unix/ $../dist/configure $make $sudo make install libevent 1.3e or later ------------------------- http://monkey.org/~provos/libevent/ How to install libevent: $tar xvzf libevent-1.3e.tar.gz $cd libevent-1.3e $./configure $make $sudo make install Load .so file by add two line in /etc/ld.so.conf: /usr/local/lib /usr/local/BerkeleyDB.4.7/lib Then, run 'ldconfig'. Installation ============ $tar xvzf memcachedb-X.Y.Z.tar.gz $cd memcachedb-X.Y.Z $./configure --enable-threads $make $sudo make install
这段是官方的,不需多解释了,安装好后启动了:
memcachedb -p21201 -d -r -u root -H ./env -N -v
解释一下,“./env”是data的目录,这个可以自己设定,这个数据是可以移植的,里面的log文件memcachedb会清理,数据文件会不会动的(废话)。
安装好后使用php的memcache扩展就可以了:
$mdb = new Memcache();
$mdb->connect('localhost', 21201);
$mdb->set($key, $result);
$value = $mdb->get($key);
这些基本的操作和对memcached的是一样,基本是memcached的协议,看到老版本对key有限制,我使用的1.2是没有这个限制了,和memcache一样,250字符够用了。和memcached不一样的地方,memcachedb(memcached默认限制1M)并没有对value的大小做限制(当然很大的话没有测试),这个是因为存储是Berkeley db,另外有点奇怪的地方,我看到源码包里面的protocal里面有这么一段:
Expiration times ---------------- Some commands involve a client sending some kind of expiration time (relative to an item or to an operation requested by the client) to the server. In all such cases, the actual value sent may either be Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds starting from current time. In the latter case, this number of seconds may not exceed 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that, the server will consider it to be real Unix time value rather than an offset from current time.
应该是没有expiration这个概念的啊,自己试了一下,发现的确没有expiration,再到官方discuss里面找,
作者回答其他人提问时也回答没有expire这个概念了。但是为什么官方文档中有这么一段呢?(可能是指memcache协议,但是放到这里会容易让人误解)。