<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>运达&#039;s  blog &#187; redis</title>
	<atom:link href="https://www.yunda51.com/?feed=rss2&#038;tag=redis" rel="self" type="application/rss+xml" />
	<link>https://www.yunda51.com</link>
	<description>运达的博客</description>
	<lastBuildDate>Wed, 12 Nov 2025 07:58:26 +0000</lastBuildDate>
	<language>zh-CN</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.19</generator>
	<item>
		<title>PHP操作redis(list)队列操作</title>
		<link>https://www.yunda51.com/?p=1976</link>
		<comments>https://www.yunda51.com/?p=1976#comments</comments>
		<pubDate>Sun, 24 Dec 2023 13:13:32 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Redis]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[抢购]]></category>
		<category><![CDATA[队列]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1976</guid>
		<description><![CDATA[好久没有更新文章了。 list使用场景如下： 消息队列 list类型的lpop和rpush（或者反过来，lpu<a href="https://www.yunda51.com/?p=1976" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p><strong>好久没有更新文章了。</strong><br />
list使用场景如下：<br />
<strong>消息队列</strong><br />
list类型的lpop和rpush（或者反过来，lpush和rpop）能实现队列的功能，故而可以用Redis的list类型实现简单的点对点的消息队列。<br />
<strong>最新列表</strong><br />
list类型的lpush命令和lrange命令能实现最新列表的功能，每次通过lpush命令往列表里插入新的元素，<br />
然后通过lrange命令读取最新的元素列表，比如评论列表、朋友圈的点赞列表。</p>
<p><strong>######消息队列demo,简单模拟抢购商品#####</strong></p>
<pre class="wp-code-highlight prettyprint">
$redis = new redis();
$redis-&gt;connect(&#039;127.0.0.1&#039;, 6379);
$redis-&gt;auth(&#039;123456&#039;);
$redis-&gt;flushAll(); //清空所有数据
/***入列***/
//用户点击抢购的时候，把商品信息存入消息队列
$key = &#039;product1&#039;;#商品1
for ($i = 0; $i &lt; 100; $i++) {
    $uid = rand(1000, 9999);
    $number = 10; //次数，假设这件商品只能10个人抢购
    if ($number &gt; $redis-&gt;lLen($key)) {
        $redis-&gt;rpush($key, $uid); //不够10个就入列
    } else {
        continue;
    }
}
/***出列***/
while (true){
    $flag = $redis-&gt;exists($key);
    if($flag){
        $uid = $redis-&gt;rpop($key);
        echo $uid .&quot;抢购成功！，进行订单处理操作&lt;br/&gt;&quot;;
    } else {
        echo &quot;出列完毕！&quot;;
        exit;
    }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1976</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CentOs下Redis的安装，配置以及phpredis扩展</title>
		<link>https://www.yunda51.com/?p=1593</link>
		<comments>https://www.yunda51.com/?p=1593#comments</comments>
		<pubDate>Thu, 13 Aug 2015 08:21:43 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[ctl]]></category>
		<category><![CDATA[redis]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1593</guid>
		<description><![CDATA[1、安装需要的支持环境 在安装Redis之前首要先做的是安装Unix的Tcl工具，如果不安装的话后期将无法对R<a href="https://www.yunda51.com/?p=1593" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>1、安装需要的支持环境</p>
<p>在安装Redis之前首要先做的是安装Unix的Tcl工具，如果不安装的话后期将无法对Redis进行测试。在后期执行make test的时候返回如下错误信息：You need tcl 8.xuyao de5 or newer in order to run the Redis test，具体的流程为：</p>
<pre class="wp-code-highlight prettyprint">cd /usr/local/src
wget http://downloads.sourceforge.net/tcl/tcl8.6.3-src.tar.gz
tar -zxvf tcl8.6.3-src.tar.gz
cd ​tcl8.6.3/unix/
./configure
make
make install
</pre>
<p>2、安装redis。<br />
先下在redis，下载地址：http://redis.io/download</p>
<pre class="wp-code-highlight prettyprint">cd /usr/local/src
wget http://download.redis.io/releases/redis-2.8.19.tar.gz
tar zxvf redis-2.8.19.tar.gz
cd redis-2.8.19
make
make PREFIX=/usr/local/redis install
</pre>
<p>3、测试Redis</p>
<pre class="wp-code-highlight prettyprint">   cd src
   make test
</pre>
<p>通过以上命令就要可以对redis进行加大的测试。</p>
<p>4、配置redis<br />
（1）复制并修改配置文档<br />
代码如下:</p>
<pre class="wp-code-highlight prettyprint">cp ./redis.conf /usr/local/redis/
vi /usr/local/redis/redis.conf
</pre>
<p>我只修改了如下两项：<br />
daemonize yes #redis将以守护进程的方式运行，默认为no会暂用你的终端<br />
timeout 300​ #当 客户端闲置多长时间后关闭连接，如果指定为0，表示关闭该功能</p>
<p>（2）设置自动启动<br />
代码如下:</p>
<pre class="wp-code-highlight prettyprint">vi /etc/init.d/redis
</pre>
<p>编辑文件保存如下内容：<br />
代码如下:</p>
<pre class="wp-code-highlight prettyprint">#!/bin/sh
#
# redis        Startup script for Redis Server
#
# chkconfig: - 80 12
# description: Redis is an open source, advanced key-value store.
#
# processname: redis-server
# config: /etc/redis.conf
# pidfile: /var/run/redis.pid
source /etc/init.d/functions
BIN=&quot;/usr/local/redis/bin&quot;
CONFIG=&quot;/usr/local/redis/redis.conf&quot;
PIDFILE=&quot;/var/run/redis.pid&quot;
### Read configuration
[ -r &quot;$SYSCONFIG&quot; ] &amp;amp;&amp;amp; source &quot;$SYSCONFIG&quot;
RETVAL=0
prog=&quot;redis-server&quot;
desc=&quot;Redis Server&quot;
start() {
        if [ -e $PIDFILE ];then
             echo &quot;$desc already running....&quot;
             exit 1
        fi
        echo -n $&quot;Starting $desc: &quot;
        daemon $BIN/$prog $CONFIG
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] &amp;amp;&amp;amp; touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
        echo -n $&quot;Stop $desc: &quot;
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] &amp;amp;&amp;amp; rm -f /var/lock/subsys/$prog $PIDFILE
        return $RETVAL
}
restart() {
        stop
        start
}
case &quot;$1&quot; in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart)
        restart
        ;;
  condrestart)
        [ -e /var/lock/subsys/$prog ] &amp;amp;&amp;amp; restart
        RETVAL=$?
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
   *)
        echo $&quot;Usage: $0 {start|stop|restart|condrestart|status}&quot;
        RETVAL=1
esac
exit $RETVAL
</pre>
<p>（3）启动服务和关闭<br />
/usr/local/redis/bin/redis-server<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/20150813161557.png"><img class="alignnone size-full wp-image-1594" src="http://www.yunda51.com/wp-content/uploads/2015/08/20150813161557.png" alt="20150813161557" width="1416" height="710" /></a><br />
表示启动成功！</p>
<p><strong>启动之后最好重新打开个窗口运行redsi-cli进入控制台</strong></p>
<p>5、使用redis</p>
<pre class="wp-code-highlight prettyprint">[root@localhost /]# cd /usr/local/redis/bin/
[root@localhost bin]# redis-cli 
127.0.0.1:6379&amp;gt; set foo ceshi
OK
127.0.0.1:6379&amp;gt; get foo
&quot;ceshi&quot;
127.0.0.1:6379&amp;gt; 
</pre>
<p>如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/redis.png"><img class="alignnone size-full wp-image-1595" src="http://www.yunda51.com/wp-content/uploads/2015/08/redis.png" alt="redis" width="1023" height="194" /></a></p>
<p>6、停止redis实例：<br />
/usr/local/redis/bin/rdis-cli shutdown 或者 pkill redis-server</p>
<p>到此为止你的redis完成，下面我们来添加phpredis安装和配置~~</p>
<p><strong>phpredis安装和配置步骤如下：</strong><br />
1、首先下载phpredis包 <a style="background: transparent none repeat scroll 0% 0%;" href="http://pan.baidu.com/s/1sjoSdLN" target=""><img class="alignnone size-full wp-image-1075" title="btn_load" src="http://www.yunda51.com/wp-content/uploads/2013/11/btn_load3.png" alt="" width="86" height="28" /></a><br />
2、解压：unzip phpredis-develop.zip<br />
3、cd phpredis-develop<br />
4、执行 /usr/local/php5/bin/phpize 会在phpredis-develop目录下生成一个configure<br />
5、./configure --with-php-config=/usr/local/php5/bin/php-config<br />
6、make<br />
7、make install<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/redis1919.png"><img class="alignnone size-full wp-image-1600" src="http://www.yunda51.com/wp-content/uploads/2015/08/redis1919.png" alt="redis1919" width="894" height="66" /></a><br />
8、执行 cd /usr/local/php5/lib/php/extensions/no-debug-non-zts-20100525/ 目录下会有redis.so<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/redis-so.png"><img class="alignnone size-full wp-image-1601" src="http://www.yunda51.com/wp-content/uploads/2015/08/redis-so.png" alt="redis-so" width="894" height="117" /></a><br />
9、vi /usr/local/php5/etc/php.ini 在php.ini添加redis.so扩展<br />
如图：<a href="http://www.yunda51.com/wp-content/uploads/2015/08/redis6.png"><img class="alignnone size-full wp-image-1602" src="http://www.yunda51.com/wp-content/uploads/2015/08/redis6.png" alt="redis6" width="279" height="78" /></a><br />
10、/etc/init.d/nginx restart 重启nginx（注：如果你们是Apache，也一样重启）。<br />
最后结果如图：<br />
<a href="http://www.yunda51.com/wp-content/uploads/2015/08/redis-success.png"><img class="alignnone size-full wp-image-1603" src="http://www.yunda51.com/wp-content/uploads/2015/08/redis-success.png" alt="redis-success" width="711" height="240" /></a><br />
这样就大功告成了，开启你得redis之旅吧，骚年~~~</p>
<p>转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a> 原文地址：<a href="http://www.yunda51.com/1470.html">http://www.yunda51.com/1593.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1593</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>windows下安装Redis+连接PHP</title>
		<link>https://www.yunda51.com/?p=1436</link>
		<comments>https://www.yunda51.com/?p=1436#comments</comments>
		<pubDate>Tue, 18 Nov 2014 10:35:55 +0000</pubDate>
		<dc:creator><![CDATA[运达]]></dc:creator>
				<category><![CDATA[Mysql]]></category>
		<category><![CDATA[php技术]]></category>
		<category><![CDATA[Redis]]></category>
		<category><![CDATA[redis]]></category>
		<category><![CDATA[wamp]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://www.yunda51.com/?p=1436</guid>
		<description><![CDATA[最近听说Redis用的人挺多的，就抽出时间研究一下，嘿嘿~~ 废话就不多说了，直接说正题！ 首先，下载Redi<a href="https://www.yunda51.com/?p=1436" class="read-more">Continue Reading</a>]]></description>
				<content:encoded><![CDATA[<p>最近听说Redis用的人挺多的，就抽出时间研究一下，嘿嘿~~ 废话就不多说了，直接说正题！</p>
<p>首先，下载Redis的windows32位客户端：<a target="_blank"  href="http://pan.baidu.com/s/12IsnO">window32位下载</a></p>
<p>下载后建议解压到web目录之类的地方，譬如：D:\WWW\Redis</p>
<p>解压完之后，打开cmd运行窗口，输入以下指令（我把redis放在了D盘www目录下面）<br />
<strong>如图</strong>：<a href="http://www.yunda51.com/wp-content/uploads/2014/11/114.jpg"><img class="alignnone size-full wp-image-1437" title="114" src="http://www.yunda51.com/wp-content/uploads/2014/11/114.jpg" alt="" width="350" height="93" /></a></p>
<p>如果你能看到CMD显示以下内容，恭喜你，你的Redis服务端已经ok了：<br />
<strong>如图</strong>：<a href="http://www.yunda51.com/wp-content/uploads/2014/11/8.jpg"><img class="alignnone size-full wp-image-1438" title="8" src="http://www.yunda51.com/wp-content/uploads/2014/11/8.jpg" alt="" width="641" height="399" /></a></p>
<p>以后要使用都可以用这个指令开启Redis，当然窗口不能关闭，关闭窗口Redis会停止运行。</p>
<p>然后：建立PHP到Redis的连接，使PHP能够直接往Redis里发送数据：</p>
<p>请运行phpinfo()查看以下内容：PHP版本号、TS or NTS、VC版本<br />
<strong>如图：</strong><a href="http://www.yunda51.com/wp-content/uploads/2014/11/1702.jpg"><img class="alignnone size-full wp-image-1439" title="1702" src="http://www.yunda51.com/wp-content/uploads/2014/11/1702.jpg" alt="" width="374" height="82" /></a></p>
<p>请选择对应的版本下载</p>
<p>php5.3-ts-vc9 （我用的是WAMP）</p>
<p>php5.4-ts-vc9 （XAMPP的一般用这个）</p>
<p>下载后请将解压得到的DLL文件拷贝到php/ext目录下，譬如我的是D:\wamp\bin\php\php5.3.10目录下</p>
<p>然后就是修改php.ini了，在你看到的一大堆extension=XXXXX.dll的后面加上以下内容（大意就是让Apache在启动的时候去加载对应扩展）：<br />
PHP5.3：extension=php_redis.dll</p>
<p>如果是PHP5.4：（顺序不可颠倒）<br />
extension=php_igbinary.dll<br />
extension=php_redis.dll</p>
<p>字段添加完后保存重启Apache（不重启是不会加载的），然后再看一下你的phpinfo里面是不是能搜到Redis扩展了，如果搜到那就恭喜你，扩展加载成功可以接着下一步了，如果搜不到也恭喜你，回头检查下哪个步骤出了问题。（如图，版本不同可以不用纠结）<br />
<strong>如图：</strong><a href="http://www.yunda51.com/wp-content/uploads/2014/11/83023.jpg"><img class="alignnone size-full wp-image-1440" title="83023" src="http://www.yunda51.com/wp-content/uploads/2014/11/83023.jpg" alt="" width="608" height="111" /></a></p>
<p>到目前安装以及配置都完事了，那么就让我们来测试一下：<br />
让我们来新建一个php文件,代码如下:</p>
<pre class="wp-code-highlight prettyprint">
&lt;?php
	$redis = new Redis();
	$redis-&gt;connect(&#039;127.0.0.1&#039;,6379);
	//$redis-&gt;connect(&quot;test.com&quot;,6379); //php客户端设置的ip及端口
	//存储一个值
	$redis-&gt;set(&quot;say&quot;,&quot;Hello World&quot;);
	echo $redis-&gt;get(&quot;say&quot;); //应输出Hello World

	//存储多个值
	$array = array(&#039;first_key&#039;=&gt;&#039;first_val&#039;,
	&#039;second_key&#039;=&gt;&#039;second_val&#039;,
	&#039;third_key&#039;=&gt;&#039;third_val&#039;);
	$array_get = array(&#039;first_key&#039;,&#039;second_key&#039;,&#039;third_key&#039;);
	$redis-&gt;mset($array);
	var_dump($redis-&gt;mget($array_get));
?&gt;
</pre>
<p>保存，运行。如果看到下图，恭喜你，开始你的Redis之旅吧！<br />
<a href="http://www.yunda51.com/wp-content/uploads/2014/11/41118183415.jpg"><img src="http://www.yunda51.com/wp-content/uploads/2014/11/41118183415.jpg" alt="" title="41118183415" width="307" height="172" class="alignnone size-full wp-image-1441" /></a><br />
转载请注明转自:<a href="http://www.yunda51.com">运达's blog</a>  原文地址：<a href="http://www.yunda51.com/1436.html">http://www.yunda51.com/1436.html</a></p>
]]></content:encoded>
			<wfw:commentRss>https://www.yunda51.com/?feed=rss2&#038;p=1436</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
