# yum --enablerepo=epel install php-pecl-redis Installed: php-pecl-redis.x86_64 0:2.2.8-1.el6 Dependency Installed: php-cli.x86_64 0:5.3.3-48.el6_8 php-common.x86_64 0:5.3.3-48.el6_8 php-pear.noarch 1:1.9.4-5.el6 php-pecl-igbinary.x86_64 0:1.2.1-1.el6 Complete!
# vi use_redis.php <?php $redis = new Redis(); $redis->connect("127.0.0.1",6381); $redis->auth("hoge"); // キーに値をセットして表示 $redis->set('key01', 'value01'); print 'key01.value : ' . $redis->get('key01') . "\n"; // キーに値をアペンドして表示 $redis->append('key01', ',value02'); print 'key01.value : ' . $redis->get('key01') . "\n"; $redis->set('key02', 1); print 'key02.value : ' . $redis->get('key02') . "\n"; // 加算 $redis->incr('key02', 100); print 'key02.value : ' . $redis->get('key02') . "\n"; // 減算 $redis->decr('key02', 51); print 'key02.value : ' . $redis->get('key02') . "\n"; // リスト $redis->lPush('list01', 'value01'); $redis->rPush('list01', 'value02'); print 'list01.value : '; print_r ($redis->lRange('list01', 0, -1)); // ハッシュ $redis->hSet('hash01', 'key01', 'value01'); $redis->hSet('hash01', 'key02', 'value02'); print 'hash01.value : '; print_r ($redis->hGetAll('hash01')); // セット $redis->sAdd('set01', 'member01'); $redis->sAdd('set01', 'member02'); print 'set01.value : '; print_r ($redis->sMembers('set01'));
# php use_redis.php key01.value : value01 key01.value : value01,value02 key02.value : 1 key02.value : 101 key02.value : 50 list01.value : Array ( [0] => value01 [1] => value02 ) hash01.value : Array ( [key01] => value01 [key02] => value02 ) set01.value : Array ( [0] => member01 [1] => member02 )