HomeDocsDevelopPHP

Documentation

PHP

Ajeet Raina
Author
Ajeet Raina, Former Developer Growth Manager at Redis

Getting Started#

Step 1. Run a Redis server#

 brew tap redis-stack/redis-stack
 brew install --cask redis-stack
INFO
 redis-cli -h localhost -p 6379
 localhost>

Step 2. Get pecl#

apt install pkg-php-tools

Step 3. Install PhpRedis#

pecl install redis

Step 4. Opening a Connection to Redis Using PhpRedis#

<?php

$redis = new Redis();
//Connecting to Redis
$redis->connect('hostname', port);
$redis->auth('password');

if ($redis->ping()) {
 echo "PONG";
}

?>

Step 5. Executing the script#

php connect.php
127.0.0.1:6379> monitor
OK
1614778301.165001 [0 [::1]:57666] "PING"

Further Reference:#

Last updated on Feb 22, 2024