#PHP EXTENSION FOR TOGO
#安装php_togo
root@localhost#wget https://github.com/SKPHP1989/php_togo/archive/master.zip
root@localhost#unzip master.zip
root@localhost#cd master
root@localhost#php-src/bin/phpize --with-php-config=php-src/bin/php-config
root@localhost#./configure
root@localhost#make && make install
修改php.ini文件 加载togo.so扩展库
重启apache或者php-fpm
检测是否已经加载togo
root@localhost#php-src/bin/php -m|grep togo
出现togo说明已经加载
##togo地址:https://github.com/zhuli/togo
功能:
1. 初始化以及常用说明
2. 计数器函数
3. 队列函数
4. 内存锁函数
#1.初始化以及常用说明
try{
$togo = new Togo;
$togo->connect('127.0.0.1' ,8787 ,5);
$togo->close();
}catch(TogoException $e){
var_dump($e)
}
##1 连接togo
host: string.
port: int.
timeout:int.
BOOL: TRUE
on success, FALSE
on error.
$togo->connect('127.0.0.1' ,8787 ,5);
##2 获取togo版本
BOOL: STRING
on success, FALSE
on error.
$togo->version();
##3 关闭togo连接
BOOL: TRUE
on success, FALSE
on error.
$togo->close();
#2.计数器函数:
##1 计数器加上某个数字,默认+1
name: string.
value: int, optional ,default 1.
BOOL: INT
on success, FALSE
on error.
$togo->counter_plus('test');
$togo->counter_plus('test' ,6);
##2 计数器减去某个数字,默认-1
name: string.
value: int, optional ,default 1.
BOOL: INT
on success, FALSE
on error.
$togo->counter_minus('test');
$togo->counter_minus('test' ,6);
##3 计数器获取一个值
name: string.
BOOL: INT
on success, FALSE
on error.
$togo->counter_get('test');
#3.队列模块协议:
##1 从左边插入一个记录
name: string.
value: int.
priority: int, optional.
BOOL: TRUE
on success, FALSE
on error.
$togo->queue_lpush('test_queue' ,1234);
$togo->queue_lpush('test_queue' ,1234 ,2);
##2 从右边插入一个记录
name: string.
value: int.
priority: int, optional.
BOOL: TRUE
on success, FALSE
on error.
$togo->queue_rpush('test_queue' ,1234);
$togo->queue_rpush('test_queue' ,1234 ,2);
##3 从左边获取一个记录
name: string.
BOOL: INT
on success, FALSE
on error.
$togo->queue_lpop('test_queue' );
##4 从右边获取一个记录
name: string.
BOOL: INT
on success, FALSE
on error.
$togo->queue_rpop('test_queue' );
##5 获取一个队列的总记录数
name: string.
BOOL: INT
on success, FALSE
on error.
$togo->queue_count('test_queue' );
##6 获取一个队列的状态
name: string.
BOOL: STRING
on success, FALSE
on error.
$togo->queue_status('test_queue' );
#4.内存锁模块协议: ##1 LOCK操作
name: string.
BOOL: TRUE
on success, FALSE
on error.
$togo->lock_lock('test_lock' );
##2 UNLOCK操作
name: string.
BOOL: TRUE
on success, FALSE
on error.
$togo->lock_unlock('test_lock' );
##3 获取一把锁的状态
name: string.
BOOL: STRING
on success, FALSE
on error.
$togo->lock_status('test_lock' );