Home  >  Article  >  Backend Development  >  Tutorial on using redis_PHP in PHP

Tutorial on using redis_PHP in PHP

WBOY
WBOYOriginal
2016-07-13 10:25:33694browse

Install redis on Mac OS
The first step is to install, it will be installed to /usr/local/bin by default

Copy the code The code is as follows :

cd /tmp
wget http://redis.googlecode.com/files/redis-2.6.9.tar.gz
tar -zxf redis-2.6.9. tar.gz
cd redis-2.6.9
make
sudo make install

and then download some configuration files (mainly opening deamon, etc., no comparison with the default Configuration difference)
Copy code The code is as follows:

wget https://github.com/ijonas/dotfiles/raw /master/etc/redis.conf
sudo mv redis.conf /etc/redis.conf
sudo /usr/local/bin/redis-server redis.conf
Please note here, if not Directory permissions cannot be established
/var/log/redis/redis.log
/var/lib/redis/

causing redis startup to fail
ok, now it’s done , your redis has been successfully run.
Try it!
Copy the code The code is as follows:

/opt/redis/redis-cli
#You will see the prompt redis 127.0.0.1:6379> indicating that the service has been connected.
set anythink helloworld
get anythink
exit

good Seeing helloworld means everything is normal.
What if I need to stop redis or restart it?
Copy code The code is as follows:

cat /opt/redis/redis.pid
#After cat, you will get a pid, mine is 44277
sudo kill 44277
# The startup method is the same as before.

Set up auto-start at boot and run in the background
Then do the following as root:
Create a new com.redis.plist under /Library/LaunchDaemons with the following content:

Copy code The code is as follows:




Dict & gt;
& lt; key & gt; label & lt;/key & gt;
& lt; strong & gt; com.redis & lt;/string & gt;
& lt; key & gt; Runtload & lt;/key & gt;
& lt; true/ >
                                                                                                                                                               etc/redis.conf

Copy code

The code is as follows:


sudo launchtcl load /Library/LaunchDaemons/com.redis.plist
sudo launchtcl start com.redis

Check the situation:Copy the code
The code is as follows:


$ cat /var/run/ redis.pid


If the pid number comes out, it means it is running~
Install the php-redis extensionIf you need to use redis in PHP, then please continue reading
Copy code

The code is as follows:

curl -O https://nodeload.github.com/nicolasff/phpredis/zip/ master
tar -zxf master
cd phpredis-master/
phpize
./configuremakesudo make install# At this time, a path will be prompted
# /usr/lib/php/extensions/no-debug-non-zts-20090626/
# means the extension has been placed at this location
vim /etc/php.ini

#Add the following content
extension=redis.so

#Restart apache
sudo httpd -k restart

#Check the extension installation status
php -m |grep redis
#The appearance of redis means the installation is successful.


If you execute phpize, the following error will appear
Cannot find autoconf. Please check your autoconf installation
and the $PHP_AUTOCONF environment variable.
Then, rerun this script.

Please download M4 separately, compile and install autoconf



Copy the code

The code is as follows:


curl -O http:// ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gzcurl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz



Note that the apache and php used above are all included with MacOS. If you install phpize yourself, please specify the absolute path.
Graphic management tool
Another: redis also has a WEB-based graphical interface management tool called phpRedisAdmin. If you just start the service, some Undefined index will appear, and it will be fine after a while. If you want to try it, you can use the following command to install it (git recommends using SourceTree to install). The management tool supports String, Hash, List, Set, Zset

Copy code Code As follows:

git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpRedisAdmin/
git clone https://github.com/nrk/predis.git

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825002.htmlTechArticleInstall redis on Mac OS. The first step is to install it. It will be installed to /usr/local/bin by default. Copy the code The code is as follows: cd /tmp wget http://redis.googlecode.com/files/redis-2.6.9.tar.gz tar -z...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn