首页 \ 问答 \ PHP memcached:getDelayed&getMulti - 如何使用?(PHP memcached: getDelayed & getMulti - how to use?)

PHP memcached:getDelayed&getMulti - 如何使用?(PHP memcached: getDelayed & getMulti - how to use?)

我最近想了一下如何在PHP应用程序中使用getDelayedgetMulti ,以及它们的区别。

从阅读有关getDelayed的文档:

“该方法不会等待响应并立即返回。当您准备收集项目时,请调用Memcached :: fetch或Memcached :: fetchAll。”

因此,与getMulti不同,显然需要在键可用之前调用fetchAll。 但是,实际的memcached调用何时完成? 在fetchAllgetDelayed运行时?

以示例更新:

    $this->memcached->set('int', 99);
    $this->memcached->set('string', 'a simple string');
    $this->memcached->set('array', array(11, 12));

    $this->memcached->getDelayed(array('int'));
    $this->memcached->getDelayed(array('string'));
    $this->memcached->getDelayed(array('array'));

    print("<pre>".print_r( $this->memcached->fetchAll() )."</pre>"); // returns the array element only.

I have thought a bit recently about how to use getDelayed and getMulti in a PHP application, and their difference.

From reading the documentation about getDelayed:

"The method does not wait for response and returns right away. When you are ready to collect the items, call either Memcached::fetch or Memcached::fetchAll."

So obviously there's a need to call fetchAll before having the keys available, unlike getMulti. But when is the actual memcached call being done? At fetchAll or when getDelayed is run?

Updated with example:

    $this->memcached->set('int', 99);
    $this->memcached->set('string', 'a simple string');
    $this->memcached->set('array', array(11, 12));

    $this->memcached->getDelayed(array('int'));
    $this->memcached->getDelayed(array('string'));
    $this->memcached->getDelayed(array('array'));

    print("<pre>".print_r( $this->memcached->fetchAll() )."</pre>"); // returns the array element only.

原文:https://stackoverflow.com/questions/2929054
更新时间:2022-01-03 11:01

最满意答案

不,它们并不总是等同,但在大多数流行的机器上,你会没事的。 calloc将一个全零的模式写入分配的内存,但空指针值在某些机器上可能不是全位零(或者甚至只是某些机器上的某些类型)。

查看C FAQ的Null Pointers部分,了解大量信息。


No, they are not always equivalent, but on most popular machines you'll be fine. calloc writes a bit pattern of all-zeros to the allocated memory, but the null pointer value might not be all-bits-zero on some machines (or even just for some types on some machines).

Check out the Null Pointers section of the C FAQ for lots and lots of information.

相关问答

更多
  • 可能存在任何问题,例如: n_tot的值可能是垃圾。 您已经在已分配的块之外编写,并且这样做会破坏用于维护堆的数据结构。 There could be any number of problems, for example: The value of n_tot could be garbage. You have written outside of an allocated block, and in doing so you have destroyed data structures used to ...
  • 你的问题的答案可能都归结为风格。 虽然你使用calloc是正确的,以确保分配的内存被清零,特别是在这样的情况下你没有在构造节点时分配所有字段,我不喜欢你依靠calloc设置0而不是具体分配上一个和下一个NULL。 你必须考虑其他人(甚至你)6个月后阅读这段代码。 通过不明确地分配prev和next到NULL,代码的意图稍微不那么明确。 像这样的东西: static struct ll_Node* ll_Node_new(void *data) { struct ll_Node *node = cal ...
  • 由于您只有一个分配来创建整个devname数组,您只需要检查该数组是否为NULL ,并且只需要释放该数组。 当你通过devname ,每个条目实际上是一个struct Devices_names ,而不是一个指针,所以它不能与NULL进行比较或以任何有意义的方式释放。 在这种情况下,您将需要一个单独的变量来跟踪有多少个条目: for (i = 0; i < devname_count; i++) { printf("Device id --- [ %d ]\n", devname[i].id); ...
  • 通常, malloc()和朋友不会仅因为您没有物理RAM而返回NULL 。 他们通常甚至不知道你有多少物理RAM,并且只是试图通过操作系统获得更多,通常使用mmap() (或brk() ,但这只是mmap()的包装器)。 mmap()也不会因为你没有物理RAM而返回失败,而是会尝试使用虚拟内存。 这在UNIX系统中很常见,并且通常不可能直接使用物理内存而不是虚拟内存。 OOM杀手只是Linux特定的实现,当虚拟内存无法处理对后备存储的需求时会发生什么。 让OOM杀手消失的一种方法是分配更多的交换空间(出于这 ...
  • 编辑清楚 我想第一个和第二个是创建一个指向5结构设备的指针。 第三个是创建一个指向结构设备的指针? 第一个malloc(number * sizeof(*devices))将分配足够的内存来存储Device的number 。 正如其他人所提到的,您可以将此块视为一个Device数组。 你得到的指针将指向块的开头。 int number = 5; Device *ptr = malloc(number * sizeof(*ptr)); /* stuff */ free(ptr); 使用calloc的第二个做 ...
  • 看起来你正在比较苹果和橘子: 当你打印a[i] is at ...指针时,你会显示数组a的元素地址 然而,当你穿上内存布局时,你会在这些地址显示值 ,这些地址本身就是指针,所以整个画面看起来很混乱。 如果您在将calloc结果分配给它们之前在a[i]处打印值,则应该获得全零,因为calloc NULL不在内存中。 分配之后,您会看到指向每个a[i]处的6字节块的指针,这非常合理。 总结一下,当你用malloc和calloc分配内存时,你最初的理解是正确的:一旦分配了一块内存,它的地址*就保持不变。 *在具有 ...
  • 您可能有一个损坏的堆,例如某些内存已过早free (并且仍然重用),或者某些缓冲区溢出(或者像ptr[-3]这样的无效访问) 您应该使用valgrind来调试此类问题。 您也可以使用Boehm的保守垃圾收集器 。 你也可以用gdb手动捕获这些bug。 使用watch gdb命令并禁用地址空间布局随机化应该会有所帮助。 我还建议总是清除一个你有free -d的指针,所以在代码中用free(x), x=NULL替换free(x), x=NULL (所以如果x被错误地取消引用,你将立即得到一个SIGSEGV ) ...
  • 问题出在这里: printf("%3d", **(arrayAscending + i)); 您正在递增指针指针。 根据我在这里看到的代码,它应该是以下内容: printf("%3d", *((*arrayAscending) + i))); 首先,您应该取消引用arrayAscending以获取指针integerArray值,并且只有在此增量之后才能使用索引。 你也可以这样写: printf("%3d",(*ayyarAscending)[i]); 但实际上更简单的只是使用索引: printf("% ...
  • 不,它们并不总是等同,但在大多数流行的机器上,你会没事的。 calloc将一个全零的模式写入分配的内存,但空指针值在某些机器上可能不是全位零(或者甚至只是某些机器上的某些类型)。 查看C FAQ的Null Pointers部分,了解大量信息。 No, they are not always equivalent, but on most popular machines you'll be fine. calloc writes a bit pattern of all-zeros to the alloc ...
  • 您没有收到编译器错误,因为语法是正确的。 什么是不正确的是逻辑,你得到的是未定义的行为,因为你正在写入缓冲区末尾的内存。 为什么它是未定义的行为? 好吧,你没有分配那个内存,这意味着它不属于你 - 你正在进入一个被警告磁带封闭的区域。 考虑您的程序是否在缓冲区后直接使用内存。 你现在已经覆盖了那个内存,因为你超过了你的缓冲区。 考虑使用像这样的大小说明符: scanf("%9s", aString); 所以你不要超过你的缓冲区。 You don't get a compiler error because ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。