PHP Use in Redis You need to use the driver library , It's very common :phpRedis and Predis
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 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 :


$redis = new Redis();
$is_connect = $redis->connect('', 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 ";

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 :


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

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