memcache初步认识(文稿)

1.认识memcache,要将它与mysql联系起来,不同的是它不会保存数据,重启后数据就没了。

2.php中使用,需要有php55-memcached或php55-memcache扩展,通过该扩展调用主机中的memcache服务器,安装memcache服务器:

brew install memcache

3.mac中将memcached设为开机启动,输入:

brew info memcached
该命令会提示设置开机启动的命令,如下:
brew info memcached
memcached: stable 1.4.20
http://memcached.org/
Conflicts with: mysql-cluster
/usr/local/Cellar/memcached/1.4.20 (10 files, 184K) *
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/memcached.rb
==> Dependencies
Required: libevent ✔
==> Options
--enable-sasl
<span style="white-space:pre">	</span>Enable SASL support -- disables ASCII protocol!
--enable-sasl-pwdb
<span style="white-space:pre">	</span>Enable SASL with memcached's own plain text password db support -- disables ASCII protocol!
==> Caveats
To have launchd start memcached at login:
    ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
Then to load memcached now:
    launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
Or, if you don't want/need launchctl, you can just run:
    /usr/local/opt/memcached/bin/memcached
复制命令:

ln -sfv /usr/local/opt/memcached/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.memcached.plist
这样开机启动就设置好了。

4.出现问题首先检查phpinfo()中是否有该扩展,该扩展的状态是否可用。然后注意扩展信息的配置,也就是链接memcache语句,以yii2为例,语句为:

'components' => [
        'cache' => [
            'class' => 'yii\caching\MemCache',
            'servers' => [
                [
                    'host' => '127.0.0.1',
                    'port' => 11211,
                    'weight' => 60,
                ],
            ],
        ],
    ],



问题1:Memcache::set(): Server 127.0.0.1 (tcp 11211) failed with: Connection refused (61)。

检查memcache是否开启,“memcached -d ” 或者“telnet localhost 11211”

问题2:Memcache::set(): php_network_getaddresses: getaddrinfo failed: nodename nor

检查服务器的地址配置是否有问题。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值