第一 下載:git上下載redis的擴展包php
git clone https://github.com/nicolasff/phpredisnode
第二 掛載:在shell中輸入 phpize 【查看適合的版本信息】git
./configure 編譯github
【phpize是用來擴展php擴展模塊的,經過phpize能夠創建php的外掛模塊】redis
注意:(phpize 若是包含多個php,必須指定位置)shell
cuihuan:phpredis cuixiaohuan$ phpizeui
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212
Cannot find autoconf. Please check your autoconf installation and thethis
$PHP_AUTOCONF environment variable. Then, rerun this script.spa
報錯的話須要安裝:brew install autoconf [phpize 報錯] 不然沒有phpize orm
[work@cuixiaozhuai phpredis]$ phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
[work@cuixiaozhuai phpredis]$ ./configure
當存在多個版本的php的時候,須要指定配置文件
./configure --with-php-config=/home/work/thirdparty/php5/bin/php-config
第三 安裝: make 以後make test 最好 make install
Build complete.
Don't forget to run 'make test'.
cuihuan:phpredis cuixiaohuan$ make test
問題報錯修復:【已修復,可是緣由可能不太準確】
make編譯報錯
.libs/redis_cluster.o(.data.rel.local+0x0): In function `ht_free_seed':
/home/work/thirdparty/php5/php5/phpredis/redis_cluster.c:226: multiple definition of `arginfo_scan'
.libs/redis.o(.data.rel.local+0xe0):/home/work/thirdparty/php5/php5/phpredis/redis.c:452: first defined here
/usr/bin/ld: Warning: size of symbol `arginfo_scan' changed from 160 in .libs/redis.o to 200 in .libs/redis_cluster.o
.libs/redis_cluster.o(.data.rel.local+0xe0): In function `create_cluster_context':
/home/work/thirdparty/php5/php5/phpredis/redis_cluster.c:276: multiple definition of `arginfo_kscan'
.libs/redis.o(.data.rel.local+0x0):/home/work/thirdparty/php5/php5/phpredis/redis.c:364: first defined here
collect2: ld returned 1 exit status
make: *** [redis.la] Error 1
最初覺得是php多個版本生成install問題,採用./configure 指定php版本,指定php位置。
可是效果仍是有問題。
最終經過修改redis_cluester.c 中,註釋掉了這兩個重複的,以後運行ok
40
41 /* Argument info for HSCAN, SSCAN, HSCAN */
42 /*ZEND_BEGIN_ARG_INFO_EX(arginfo_kscan, 0, 0, 2)
43 ZEND_ARG_INFO(0, str_key)
44 ZEND_ARG_INFO(1, i_iterator)
45 ZEND_ARG_INFO(0, str_pattern)
46 ZEND_ARG_INFO(0, i_count)
47 ZEND_END_ARG_INFO();
48 */
49
50 /* Argument infor for SCAN */
51 /*
52 ZEND_BEGIN_ARG_INFO_EX(arginfo_scan, 0, 0, 2)
53 ZEND_ARG_INFO(1, i_iterator)
54 ZEND_ARG_INFO(0, str_node)
55 ZEND_ARG_INFO(0, str_pattern)
56 ZEND_ARG_INFO(0, i_count)
57 ZEND_END_ARG_INFO();
58 */
進行簡單的php操做
<?php
$redis = new Redis();
$conn = $redis->connect('127.0.0.1',6379);
echo "redis pass and status show</br>";
var_dump($redis->ping());
$redis->set('test_key','test_value');
echo "test set val=".$redis->get('test_key')."</br>";
$redis->setnx('unique_key',"unique_val");
$redis->setnx('unique_key',"unique_val_2");
echo $redis->get("unique_key");
//sleep(60);
echo 'is exist'.$redis->exists('test_60s');
echo 'not has value'.$redis->get('test_60s');
$redis->delete('test_key','test_60s');