Thursday, February 17, 2022

How To Use Redis in PHP | Example To Use Redis on PHP

 in This Tutorial you will Learn "  How To Use Redis in PHP| Example To Use Redis on PHP "
Redis is an open source key-value store that functions as a data structure server.
PHP is a server side scripting language.
_________________________________________________________________________________________
Server - Os:  Rocky Linux 8.5  64Bit      | IP -192.168.1.60        |Hostname - server.yourdomain.com
_________________________________________________________________________________________
cat /etc/system-release ; hostname ; hostname -I ; dnf groupinstall "Development Tools" -y
dnf makecache ; dnf install redis -y
systemctl start redis ; systemctl enable redis
gedit  /etc/redis.conf &>/dev/null
# requirepass password
systemctl restart redis ; systemctl status redis
redis-cli

dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
dnf module list php
dnf module reset php -y
dnf module enable php:remi-7.4 -y
dnf install php -y
dnf install -y php-pecl-redis5
php -m | grep redis
_________________________________________________________________________________________
Example 1 -
_________________________________________________________________________________________
nano use_redis.php
<?php
 
$redis = new Redis();
//Connecting to Redis
$redis->connect('127.0.0.1', 6379);
$redis->auth('password');
 
if ($redis->ping()) {
 echo "PONG";
}
 
?>
php use_redis.php
_________________________________________________________________________________________
Example 2 -
_________________________________________________________________________________________
nano connect.php
<?php
// connecting to Redis server on localhost
$redis = new Redis();
$redis->connect('127.0.0.1', 6379);
echo "Connection successful";
php connect.php
________________________________________________________________________________________


No comments:

Post a Comment