安装Tokyo Cabinet,后端存储:
yum install gcc zlib-devel bzip2-devel
wget http://fallabs.com/tokyocabinet/tokyocabinet-1.4.48.tar.gz
tar zxvf tokyocabinet-1.4.48.tar.gz
cd tokyocabinet-1.4.48/
./configure --prefix=/usr/local/tokyocabinet-1.4.48/
make && make install
安装Tokyo Cabinet PHP扩展:
git clone https://github.com/rsky/php-tokyocabinet.git
cd php-tokyocabinet/
phpize
export PKG_CONFIG_PATH=/usr/local/tokyocabinet-1.4.48/lib/pkgconfig/
./configure --enable-tokyocabinet
make && make install
echo "extension=tokyocabinet.so" >> /etc/php.ini
使用:
<?php
$bdb = new TCBDB();
$bdb->open('tc.bdb', TCBDB::OWRITER | TCBDB::OCREAT);
$bdb->put('key', 'value');
echo $bdb->get('key'), "\n";
?>
安装Tokyo Cabinet Lua扩展:
yum install lua-devel
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/tokyocabinet-1.4.48/include/
wget http://fallabs.com/tokyocabinet/luapkg/tokyocabinet-lua-1.10.tar.gz
tar zxvf tokyocabinet-lua-1.10.tar.gz
cd tokyocabinet-lua-1.10
./configure --prefix=/usr/local/tokyocabinet-lua-1.10
make && make install
安装Tokyo Tyrant,网络前端:
wget http://fallabs.com/tokyotyrant/tokyotyrant-1.1.41.tar.gz
tar zxvf tokyotyrant-1.1.41.tar.gz
cd tokyotyrant-1.1.41
./configure --prefix=/usr/local/tokyotyrant-1.1.41/ --enable-lua \
--with-tc=/usr/local/tokyocabinet-1.4.48/
make && make install
cp -r ext/ /etc/ttserver
echo "/usr/local/tokyotyrant-1.1.41/lib/" >> /etc/ld.so.conf.d/tokyo.conf
echo "/usr/local/tokyocabinet-1.4.48/lib" >> /etc/ld.so.conf.d/tokyo.conf
ldconfig
启动Tokyo Tyrant:
ttserver -host 127.0.0.1 -port 1978 -thnum 8 -dmn -pid /tmp/ttserver.pid -log /tmp/ttserver.log -le \
-ulog /tmp/ -ulim 32m -sid 1 -rts /tmp/ttserver.rts -ext /etc/ttserver/queue.lua /tmp/database.tch
Tokyo Tyrant通过tcrdbext.c对Lua提供了API,可使用Lua脚本扩展Tokyo Tyrant服务端功能。
更多:http://fallabs.com/tokyotyrant/spex.html#luaext
安装Tokyo Tyrant PHP扩展:
git clone https://github.com/mkoppanen/php-tokyo_tyrant.git
cd php-tokyo_tyrant/
phpize
./configure --with-tokyo-tyrant=/usr/local/tokyotyrant-1.1.41/ \
--with-tokyo-cabinet-dir=/usr/local/tokyocabinet-1.4.48/
make && make install
echo 'extension=tokyo_tyrant.so' >> /etc/php.ini
测试:
<?php
$tt = new TokyoTyrant("localhost", '1978');
$tt->put("key", "value");
echo $tt->get("key");
for($i=1; $i<=100; $i++)
{
$tt->ext('enqueue','0', 'my_queue', $i );
}
print_r($tt->ext('dequeue', '0','my_queue', 10));
print_r($tt->ext('dequeue', '0','my_queue', 10));
print_r($tt->ext('dequeue', '0','my_queue', 10));
//上面ext方法的第2个参数0,为是否开启锁机制,还有下面两个值可选:
//一个相当于行锁,一个相当于表锁,一般第一个就够用了
//Tyrant::XOLCKREC for record locking
//Tyrant::XOLCKGLB for global locking
?>
使用客户端管理:
tcrmgr put -port 1978 127.0.0.1 key1 value1
tcrmgr ext -port 1978 127.0.0.1 enqueue myqueue value1
curl -X PUT http://192.168.1.3:1978/key1 -d "value1"
curl http://127.0.0.1:1978/key1
标签:none