PHP Use in Redis You need to use the driver library , It's very common :phpRedis and Predis
1、phpRedis
phpRedis yes C The realization of a php Of pecl Expand ,php The related classes provided by the extension are directly used in the code 、 The method can . So using this extension needs to be in php The extension library adds a c The expansion of language writing php-redis.dll or redis.so And so on , And configure php.ini, The installation of the extension itself has no external dependencies , Because the internal implementation uses php Layer encapsulated streem Flow operation . The only problem with this extension is configuration .

Usage method :

<?php

$redis = new Redis();
$is_connect = $redis->connect('127.0.0.1', 6379);

if ($is_connect) {
echo " Connect redis success ";
$redis->set("a", "a_value"); // Go to redis Write a string
$redis->get("a"); // from redis Read one in string
$redis->delete("a"); // from redis Delete one from string
} else {
echo " Connect redis Failure ";
}

2、Predis
predis yes PHP Version written redis client, use socket Connect .Predis More in line with phper Usage habits , Forget the cumbersome configuration , Using native PHP Code implementation of a set of Redis-client Program , You don't have to install any extensions , Just introduce php Code can be very convenient to use redis.
Because it's a native php package , And support composer, So it's more convenient to use , After the introduction, you can :

<?php

$client = new Predis\Client([
'scheme' => 'tcp',
'host' => '127.0.0.1',
'port' => 6379,
]);

$client->set('a', 'a-value');// Set up 1 individual string
$client->get('a');// Read 1 individual string