Home >Database >Redis >Introduction to the installation and use of redis extension in mac environment

Introduction to the installation and use of redis extension in mac environment

尚
forward
2020-05-26 09:02:093218browse

Introduction to the installation and use of redis extension in mac environment

redis is a high-performance key-value database. The emergence of redis has largely compensated for the shortcomings of key/value storage such as memcached, and can play a very good supplementary role to relational databases in some situations. It is written in ANSI C language, supports network, can be memory-based and persistent log type, and provides APIs in multiple languages.

Mac itself comes with a PHP environment, but the redis extension is not installed. We need to install it separately. Below I will talk about the installation steps and what needs to be paid attention to.

Installing and starting redis

1. Unzip the downloaded redis to the /usr/local directory and run the command: tar -zxvf redis-5.0.5.tar.gz -C / usr/local/redis-5.0.5

2. The terminal enters the decompressed root directory: cd /usr/local/redis-5.0.5

3. Test compilation: sudo make test

4. Install redis: sudo make install

If the following error is reported during the test in step 4:

Executing test client: couldn't execute "src/ redis-benchmark": no such file or directory.

Perform the following two steps

(1),sudo make distclean

(2),sudo make

5. Configuration

After the above installation is successful, configure the php.ini file:

extension_dir = "/usr/lib/php/extensions/no-debug- non-zts-20131226/"

#The address here is the location where redis.so is installed in your reids.

extension = redis.so

6. Print out phpinfo() to see if the installation is successful. If you can see the following information, the installation is successful.

Introduction to the installation and use of redis extension in mac environment

(Check whether redis is installed successfully: You can also execute make test after the installation is completed, and [o/ All tests passed without errors!] [Cleanup: may take some time. .. OK】Indicates that redis is installed successfully.)

7. Modify [daemonize no] in redis.conf in the redis root directory to [daemonize yes] to start in background running mode

8. Start redis executes the command in the redis root directory: ./src/redis-server ./redis.conf. To stop the redis service, you can execute the client command: ./src/redis-cli shutdown

9. Log in to the client command. For: [./src/redis-cli] or [./src/redis-cli -p 6379] or [telnet 127.0.0.1 6379], execute it in the root directory of the redis installation folder.

Testing redis

After completing the installation and starting redis, log in to the client to test redis.
Example:

127.0.0.1:6379> set key "success"  //写入数据
OK
127.0.0.1:6379> get key  //读取数据
"success"
127.0.0.1:6379>

Problem summary

1. When sudo make install prompts

Installing shared extensions: /usr/lib/php/extensions/no-debug- non-zts-20131226/
cp: /usr/lib/php/extensions/no-debug-non-zts-20131226/#INST@12567#: Operation not permitted
make: * [install-modules] Error 1

Solution:mac php installation extension make install not permit

2. After installation, configure the php.ini file

in the file extension=redis.so was added. When testing redis, it was found that it did not come out.

Solution:
extension_dir = "/usr/local/php/lib/php/extensions/no-debug-zts-20090626" #In the address, write the address returned by make install

extension=redis.so

For more redis knowledge, please pay attention to the redis introductory tutorial column.

The above is the detailed content of Introduction to the installation and use of redis extension in mac environment. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete