Redis supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs and geospatial indexes with radius queries.
Install PHP 7 through IUS Community repositories:
http://blog.ijun.org/2016/03/install-php-7-on-centos-through-ius.html
Install Redis 3 through IUS Community repositories:
# yum install redis30u
# systemctl enable redis.service
# systemctl start redis.service
# redis-cli ping
PONG
# ss -nlp | grep redis
tcp LISTEN 0 128 127.0.0.1:6379 *:* users:(("redis-server",pid=1234,fd=4))
Install Redis PHP 7 client:
# yum install gcc gcc-c++ make
# cd /tmp
# wget https://github.com/phpredis/phpredis/archive/php7.zip -O phpredis.zip
# unzip -o /tmp/phpredis.zip && mv /tmp/phpredis-* /tmp/phpredis
# cd /tmp/phpredis && phpize && ./configure && make && make install
# echo 'extension=redis.so' >> /etc/php.d/30-redis.ini
# php -r "if (new Redis() == true){ echo \"OK \r\n\"; }"
OK
Listen to other interfaces:
# vim /etc/redis.conf
bind 192.168.0.1 127.0.0.1
Restart Redis server:
# systemctl restart redis
Check the listening interfaces:
# ss -ln | grep 6379
tcp LISTEN 0 128 127.0.0.1:6379 *:*
tcp LISTEN 0 128 192.168.10.41:6379 *:*
test.php:
<?php
$test = [
'status' => TRUE,
'msg' => 'ok',
];
$redis = new Redis();
$redis->connect('127.0.0.1');
$redis->set('sb_test1', json_encode($test));
$test['hmm'] = 'HMM';
$redis->set('sb_test2', json_encode($test));
$sb_test1 = $redis->get('sb_test1');
$sb_test2 = $redis->get('sb_test2');
echo $sb_test1 . PHP_EOL;
echo $sb_test2 . PHP_EOL;
$allKeys = $redis->keys('*');
print_r($allKeys);
$redis->close();
?>
Reference:
https://github.com/phpredis/phpredis
https://anton.logvinenko.name/en/blog/how-to-install-redis-and-redis-php-client.html
http://redis.io/
No comments:
Post a Comment