predisHow can I install and use Redis on a MacOS system with PHP?
To install and use Redis on a MacOS system with PHP, you can follow the steps below:
-
Install Homebrew (a package manager for MacOS) by running the command:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
-
Install Redis using Homebrew by running the command:
brew install redis
-
Start Redis by running the command:
brew services start redis
-
Install the PHP extension for Redis by running the command:
pecl install redis
-
Enable the Redis extension in your
php.ini
file:extension=redis.so
-
Test the connection to Redis with a simple PHP script:
<?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379); echo "Connection to server sucessfully"; // Check if server is running echo "Server is running: " . $redis->ping(); ?>
Output:
Connection to server sucessfully Server is running: +PONG
-
You can now use Redis with your PHP scripts!
Helpful links
More of Predis
- How can I use PHP and Redis to retrieve a range of values from a sorted set?
- How do I install PHP Redis on Ubuntu 20.04?
- How can I use the zscan command in PHP with Redis?
- How can I use PHP to increment values in Redis using ZINCRBY?
- How can I use PHP and Redis to retrieve data from a sorted set using ZRANGEBYSCORE?
- How can I use PHP and Redis to get a reverse range of scores?
- How can I use Redis with the Yii PHP framework?
- How do I delete a key in PHP using Redis?
- How do I install Predis on Ubuntu using PHP?
- How do I save an object in Redis using PHP?
See more codes...