/** * FetchAll * * @throws Exception * @return array */ public function fetchAll() { $result = $this->memcached->fetchAll(); if ($result === false) { throw new Exception\RuntimeException("Memcached::fetchAll() failed"); } $select = $this->stmtOptions['select']; foreach ($result as &$elem) { if (!in_array('key', $select)) { unset($elem['key']); } } return $result; }
public function setUp() { if (!class_exists('\\Memcached', true)) { $this->markTestSkipped('Memcached is not installed'); } $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); // setup the default timeout (avoid max execution time) socket_set_option($socket, SOL_SOCKET, SO_SNDTIMEO, array('sec' => 1, 'usec' => 0)); $result = @socket_connect($socket, '127.0.0.1', 11211); if (!$result) { $this->markTestSkipped('Memcached is not running'); } socket_close($socket); $memcached = new \Memcached(); $memcached->addServer('127.0.0.1', 11211); $memcached->fetchAll(); }
/** * FetchAll * * @throws Exception * @return array */ public function fetchAll() { $prefixL = strlen($this->stmtOptions['namespace'] . $this->getOptions()->getNamespaceSeparator()); $result = $this->memcached->fetchAll(); if ($result === false) { throw new Exception\RuntimeException("Memcached::fetchAll() failed"); } $select = $this->stmtOptions['select']; foreach ($result as &$elem) { if (in_array('key', $select)) { $elem['key'] = substr($elem['key'], $prefixL); } else { unset($elem['key']); } } return $result; }
/** * Remove an item from the cache. * * @param string $key * @return bool */ public function forget($key) { if ($key == '*') { $this->flush(); return true; } $pattern = str_replace(['\\*', '*'], '.+', preg_quote($this->getPrefixWithLocale(true) . $key)); $check = true; $all = $this->memcached->fetchAll(); if ($all) { $check = false; foreach ($all as $cache) { if (preg_match('~^' . $pattern . '$~i', $cache['key'])) { if (!$this->memcached->delete($cache['key'])) { $check = false; } } } } return $check; }
public function testFetchAllEmptyResults() { $memcached = new Memcached(); $this->assertFalse($memcached->fetchAll()); }
<?php session_start(); $m = new Memcached(); $m->addServer('localhost', 11211); $m->set('key', 'value', time() + 30); $m->delete('key1'); $m->fetchAll(); // var_dump($m); $memcache = new Memcache(); $memcache->connect('localhost', 11211) or die("Could not connect"); $version = $memcache->getVersion(); echo "Server's version: " . $version . "<br/>\n"; $tmp_object = new stdClass(); $tmp_object->str_attr = 'test'; $tmp_object->int_attr = 123; $memcache->set('key', $tmp_object, false, 10) or die("Failed to save data at the server"); echo "Store data in the cache (data will expire in 10 seconds)<br/>\n"; $get_result = $memcache->get('key'); echo "Data from the cache:<br/>\n"; var_dump($get_result);
/** * Fetch all remaining results from the last request. * * @link http://www.php.net/manual/en/memcached.fetchall.php * * @return array|bool Returns the results or FALSE on failure. */ public function fetchAll() { return $this->m->fetchAll(); }
/** * @inheritdoc */ public function getAll() { return $this->storage->fetchAll(); }
/** * Fetch all remaining results from the last request. * * @link http://www.php.net/manual/en/memcached.fetchall.php * * @return array|bool Returns the results or FALSE on failure. */ public function fetchAll() { return $this->daemon->fetchAll(); }