memcache连接vs addServer [英] memcache connect vs addServer

查看:52
本文介绍了memcache连接vs addServer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看有关Memcache的 php文档,但发现它没有这样做
$mem->connect('localhost', 11211)我可以代替
$mem->addServer('localhost', 11211)

I was looking at the php docs on memcache and noticed that instead of doing
$mem->connect('localhost', 11211) I can do instead
$mem->addServer('localhost', 11211)

这样,如果我最终不使用内存缓存连接,它将不会打扰连接.

And this way if I don't end up using the memcache connection, it won't bother connecting.

这让我想知道,为什么有人会使用connect()而不是addServer()?

This got me wondering, why would someone ever use connect() over addServer()?

这似乎是可能的不必要连接.我想念什么吗?

It just seems like a possible unnecessary connection. Am I missing something?

推荐答案

pconnect 似乎级别较低呼叫,执行一项任务而没有太多的开销. addServer OTOH级别更高,可以管理多个服务器,并在以下情况下重试其中之一失败了,等等.我的印象是,后者依靠前者来完成任务.

connect and pconnect seem to be more low level calls, that perform a single task without much overhead. addServer OTOH is more high level, managing several servers, retrying when one of them fails, etc. I'm under the impression that the latter relies on the former to do its task.

从最终用户的角度来看,使用较低级别的功能几乎没有什么优势,除了可能会带来一点性能改进(如果您知道,您将立即使用连接,只有单个Memcached服务器,无需保持持久连接-或实际上想要对其进行重置以进行故障排除等-仅按需连接可能会更快).仅当您需要对连接生命周期进行更多控制(例如,如果您正在设计自己的缓存策略)时,这些功能才有用.

From the end-user perspective, there's really little advantage in using the lower level function, except perhaps as a small performance improvement (if you know you'll use the connection right away, only have a single memcached server and don't need to keep a persistent connection - or actually wants to reset it for troubleshooting etc - it might be faster to just connect on demand). Only if you need more control over the connection lifecycle (for instance if you're designing your own caching strategy) those functions will be useful.

换句话说,这些函数在API中公开的事实并不意味着它们会存在一个通用的用例.不过,提供更多工具与系统交互通常要好得多,因为它鼓励平台构建.

In other words, the fact that those functions are exposed in the API doesn't imply there will be a common use case for them. Still, it's often better to provide more tools to interact with a system than less, since it encourages platform building.

这篇关于memcache连接vs addServer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆