Home > Backend Development > PHP Tutorial > Linux installation redis service and php redis extension

Linux installation redis service and php redis extension

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-29 09:13:33
Original
868 people have browsed it

Please support for more: http://www.webyang.net/Html/web/article_174.html

One: redis installation

Download, extract and compile Redis with:
<ol>
<li value="1">
<span>$ wget http</span><span>:</span><span>//download.redis.io/releases/redis-3.0.4.tar.gz</span>
</li>
<li>
<span>$ tar xzf redis</span><span>-</span><span>3.0</span><span>.</span><span>4.tar</span><span>.</span><span>gz</span>
</li>
<li>
<span>$ cd redis</span><span>-</span><span>3.0</span><span>.</span><span>4</span>
</li>
<li><span>$ make</span></li>
</ol>
Copy after login
The binaries that are now compiled are available in the src directory. Run Redis with:
<ol><li value="1">
<span>$ src</span><span>/</span><span>redis</span><span>-</span><span>server</span>
</li></ol>
Copy after login
You can interact with Redis using the built-in client:
<ol><li value="1">
<span>$ src</span><span>/</span><span>redis</span><span>-</span><span>cli</span>
</li></ol>
Copy after login
redis> set foo bar
OK
redis> get foo
"bar"
More: http://www.redis.io/ download
2. PHP extension:
More versions: http://pecl.php.net/package/redis After the installation of
<ol>
<li value="1">
<span>wget http</span><span>:</span><span>//pecl.php.net/get/redis-2.2.5.tgz</span>
</li>
<li><span>#解压</span></li>
<li>
<span>tar zxvf redis</span><span>-</span><span>2.2</span><span>.</span><span>5.tgz</span>
</li>
<li><span>#进入安装目录</span></li>
<li>
<span>cd redis</span><span>-</span><span>2.2</span><span>.</span><span>5</span>
</li>
<li>
<span>/</span><span>usr</span><span>/</span><span>local</span><span>/</span><span>php</span><span>/</span><span>bin</span><span>/</span><span>phpize</span>
</li>
<li><span>#配置</span></li>
<li>
<span>./</span><span>configure </span><span>--</span><span>with</span><span>-</span><span>php</span><span>-</span><span>config</span><span>=</span><span>/usr/</span><span>local</span><span>/</span><span>php</span><span>/</span><span>bin</span><span>/</span><span>php</span><span>-</span><span>config</span>
</li>
<li><span>#编译安装</span></li>
<li>
<span>make  </span><span>&&</span><span> make install</span>
</li>
</ol>
Copy after login
is completed, the following installation path appears
/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
Configure PHP support
#Edit the configuration file and add the following content in the last line
<ol>
<li value="1">
<span>vim </span><span>/</span><span>usr</span><span>/</span><span>local</span><span>/</span><span>php</span><span>/</span><span>etc</span><span>/</span><span>php</span><span>.</span><span>ini  </span>
</li>
<li>
<span>extension</span><span>=</span><span>"redis.so"</span>
</li>
</ol>
Copy after login
At this time, phpinfo() can see the redis extension.
Redis small example:
<ol>
<li value="1">
<span>$redis </span><span>=</span><span>new</span><span> redis</span><span>();</span>
</li>
<li>
<span>$test</span><span>=</span><span>$redis</span><span>-></span><span>connect</span><span>(</span><span>'127.0.0.1'</span><span>,</span><span>6379</span><span>);</span>
</li>
<li>
<span>var_dump</span><span>(</span><span>$test</span><span>);</span>
</li>
<li><span> </span></li>
<li>
<span>$result </span><span>=</span><span> $redis</span><span>-></span><span>set</span><span>(</span><span>'test'</span><span>,</span><span>"webyang.net"</span><span>);</span>
</li>
<li>
<span>var_dump</span><span>(</span><span>$result</span><span>);</span><span>//结果:bool(true)</span>
</li>
<li><span> </span></li>
<li>
<span>$result </span><span>=</span><span> $redis</span><span>-></span><span>get</span><span>(</span><span>'test'</span><span>);</span>
</li>
<li>
<span>var_dump</span><span>(</span><span>$result</span><span>);</span><span>//结果:string(11) "webyang.net"</span>
</li>
</ol>
Copy after login

The reason why we do this is because the company uses Alibaba’s RDS. Occasionally, when the concurrency is high, it will freeze, and the CPU will directly run 100%. RDS has 12g of memory, maximum IOPS 6000, and maximum number of links. 2000. In fact, we are far from reaching this number, so we are considering building a redisqueue for fun, and put some things that are not necessary to be executed in real time into the queue for execution. I originally wanted to set up the queue to be executed directly after a few minutes after the data is stored. I didn't think of a good way. I could only write a script in Linux and run it every few minutes. In fact, relatively speaking, this is not very smart. , there is some waste of resources, do you have any good ideas? Please brainstorm~ The above introduces the Linux installation of redis service and PHP redis extension, including queue content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
Statement of this Website
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
Latest Issues
php redis connection problem
From 1970-01-01 08:00:00
0
0
0
About a small error in the redis manual
From 1970-01-01 08:00:00
0
0
0
python2.7 - django cannot connect to redis
From 1970-01-01 08:00:00
0
0
0
I can't connect to redis using php
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template