/** * Fetches the next item from result set * * @return array|boolean The next item or false * @see fetchAll() * * @triggers fetch.pre(PreEvent) * @triggers fetch.post(PostEvent) * @triggers fetch.exception(ExceptionEvent) */ public function fetch() { if (!$this->stmtActive) { return false; } $args = new ArrayObject(); try { $eventRs = $this->triggerPre(__FUNCTION__, $args); if ($eventRs->stopped()) { return $eventRs->last(); } $result = $this->memcached->fetch(); if (!empty($result)) { $select =& $this->stmtOptions['select']; // handle selected key if (!in_array('key', $select)) { unset($result['key']); } // handle selected value if (!in_array('value', $select)) { unset($result['value']); } } else { // clear stmt $this->stmtActive = false; $this->stmtOptions = null; } return $this->triggerPost(__FUNCTION__, $args, $result); } catch (\Exception $e) { return $this->triggerException(__FUNCTION__, $args, $e); } }
/** * Internal method to fetch the next item from result set * * @return array|boolean The next item or false * @throws Exception\ExceptionInterface */ protected function internalFetch() { if (!$this->stmtActive) { return false; } $result = $this->memcached->fetch(); if (!empty($result)) { $select = & $this->stmtOptions['select']; // handle selected key if (!in_array('key', $select)) { unset($result['key']); } // handle selected value if (!in_array('value', $select)) { unset($result['value']); } } else { // clear stmt $this->stmtActive = false; $this->stmtOptions = null; } return $result; }
/** * Fetches the next item from result set * * @return array|boolean The next item or false * @see fetchAll() * * @triggers fetch.pre(PreEvent) * @triggers fetch.post(PostEvent) * @triggers fetch.exception(ExceptionEvent) */ public function fetch() { if (!$this->stmtActive) { return false; } $args = new ArrayObject(); try { $eventRs = $this->triggerPre(__FUNCTION__, $args); if ($eventRs->stopped()) { return $eventRs->last(); } $prefixL = strlen($this->stmtOptions['namespace'] . $this->getOptions()->getNamespaceSeparator()); if (!$this->stmtIterator) { // clear stmt $this->stmtActive = false; $this->stmtIterator = null; $this->stmtOptions = null; $result = false; } else { $result = $this->memcached->fetch(); if (!empty($result)) { $select = $this->stmtOptions['select']; if (in_array('key', $select)) { $result['key'] = substr($result['key'], $prefixL); } } } return $this->triggerPost(__FUNCTION__, $args, $result); } catch (\Exception $e) { return $this->triggerException(__FUNCTION__, $args, $e); } }
public function testGetDelayedSuccess() { $request = new MemcacheGetRequest(); $request->addKey("key"); $request->addKey("bar"); $request->setForCas(true); $response = new MemcacheGetResponse(); $item = $response->addItem(); $item->setKey("key"); $item->setValue("value"); $item->setFlags(0); // string. $item->setCasId(123456); $item = $response->addItem(); $item->setKey("bar"); $item->setValue("bar_value"); $item->setFlags(0); // string. $item->setCasId(2); $cb_count = 0; $cb = function ($val) use(&$cb_count) { $cb_count++; }; $this->apiProxyMock->expectCall('memcache', 'Get', $request, $response); $memcached = new Memcached(); $this->assertTrue($memcached->getDelayed(["key", "bar"], true, $cb)); $this->assertEquals($memcached->getResultCode(), Memcached::RES_SUCCESS); $result = $memcached->fetch(); $this->assertEquals($result["key"], "key"); $this->assertEquals($result["value"], "value"); $this->assertEquals($result["cas"], 123456); $result = $memcached->fetch(); $this->assertEquals($result["key"], "bar"); $this->assertEquals($result["value"], "bar_value"); $this->assertEquals($result["cas"], 2); $this->assertFalse($memcached->fetch()); $this->assertEquals($cb_count, 2); $this->apiProxyMock->verify(); }
/** * Fetch the next result. * * @link http://www.php.net/manual/en/memcached.fetch.php * * @return array|bool Returns the next result or FALSE on failure. */ public function fetch() { return $this->m->fetch(); }
<?php $m = new Memcached(); $m->addServer('127.0.0.1', 11211); $m->set('foo', 'bar'); $m->set('foo2', 'bar2'); $m->getDelayed(array('foo', 'foo2'), true); while ($result = $m->fetch()) { var_dump($result); }
/** * Fetch the next result. * * @link http://www.php.net/manual/en/memcached.fetch.php * * @return array|bool Returns the next result or FALSE on failure. */ public function fetch() { return $this->daemon->fetch(); }