Use redis in PHP
- 2020-11-03 22:02:45
- OfStack
Install redis on Mac OS
The first is the installation, which will be installed under /usr/local/bin by default
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
Then download 1 configuration file (basically open deamon and so on, no difference from the default configuration)
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
Having said that, if you don't have directory permission, you can't set it up
/var/log/redis/redis.log
/var/lib/redis/
Causes redis to fail to start
ok, now that you're done, your redis is up and running.
Give it a try!
/opt/redis/redis-cli
# You'll see the prompt redis 127.0.0.1:6379> Indicates that the service is connected.
set anythink helloworld
get anythink
exit
good sees helloworld, indicating that 1 cut is normal.
What if I need to stop redis or restart it?
cat /opt/redis/redis.pid
#cat After get 1 a pid, My is 44277
sudo kill 44277
# Start method and before 1 The sample.
Set startup and background operation
Then, as root, do the following:
Under /Library/LaunchDaemons, create com.redis.plist, which reads as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.redis</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/redis-server</string>
<string>/etc/redis.conf</string>
</array>
</dict>
</plist>
Run after
sudo launchtcl load /Library/LaunchDaemons/com.redis.plist
sudo launchtcl start com.redis
Check 1:
$ cat /var/run/redis.pid
If the number pid comes out, it is running ~
Install the ES50en-redis extension
If you need to use redis in PHP, read on
curl -O https://nodeload.github.com/nicolasff/phpredis/zip/master
tar -zxf master
cd phpredis-master/
phpize
./configure
make
sudo make install
# And that's when you'll notice 1 A path
# /usr/lib/php/extensions/no-debug-non-zts-20090626/
# Indicates that the extension has been placed in that location
vim /etc/php.ini
# Add the following
extension=redis.so
# restart apache
sudo httpd -k restart
# View the extension installation
php -m |grep redis
# appear redis Indicates successful installation.
If phpize is executed, the following error is indicated
Cannot find autoconf. Please check your autoconf installation
and the $PHP_AUTOCONF environment variable.
Then, rerun this script.
Please download M4 and autoconf respectively
curl -O http://ftp.gnu.org/gnu/m4/m4-1.4.9.tar.gz
curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-2.62.tar.gz
Note that the apache and php used above are the own ones of MacOS. If you install phpize yourself, please specify the absolute path.
Graphical management tool
redis also has a graphical interface management tool based on WEB, called phpRedisAdmin. If you start the service, there will be some Undefined index, after 1 will be fine. If you want to try it out, you can use the following command to install (git is recommended to install SourceTree). The management tool supports String, Hash, List, Set, Zset
git clone https://github.com/ErikDubbelboer/phpRedisAdmin.git
cd phpRedisAdmin/
git clone https://github.com/nrk/predis.git