public function testScalars() { // Basic get/set $this->credis->set('foo', 'FOO'); $this->assertEquals('FOO', $this->credis->get('foo')); $this->assertFalse($this->credis->get('nil')); // Empty string $this->credis->set('empty', ''); $this->assertEquals('', $this->credis->get('empty')); // UTF-8 characters $utf8str = str_repeat("quarter: ¼, micro: µ, thorn: Þ, ", 500); $this->credis->set('utf8', $utf8str); $this->assertEquals($utf8str, $this->credis->get('utf8')); // Array $this->assertTrue($this->credis->mSet(array('bar' => 'BAR', 'apple' => 'red'))); $mGet = $this->credis->mGet(array('foo', 'bar', 'empty')); $this->assertTrue(in_array('FOO', $mGet)); $this->assertTrue(in_array('BAR', $mGet)); $this->assertTrue(in_array('', $mGet)); // Non-array $mGet = $this->credis->mGet('foo', 'bar'); $this->assertTrue(in_array('FOO', $mGet)); $this->assertTrue(in_array('BAR', $mGet)); // Delete strings, null response $this->assertEquals(2, $this->credis->del('foo', 'bar')); $this->assertFalse($this->credis->get('foo')); $this->assertFalse($this->credis->get('bar')); // Long string $longString = str_repeat(md5('asd'), 4096); // 128k (redis.h REDIS_INLINE_MAX_SIZE = 64k) $this->assertTrue($this->credis->set('long', $longString)); $this->assertEquals($longString, $this->credis->get('long')); }
protected function setUp() { $client = new \Credis_Client(self::REDIS_HOST, self::REDIS_PORT); $client->del('foo'); $client->del('key1'); $client->del('key2'); $this->keyValueStore = new CredisKeyValueStore($client); }
/** * 清楚redis中的所有缓存 */ public function flush() { if ($this->_prefix) { $keys = $this->_client->keys($this->_prefix); } else { $keys = $this->_client->keys("*"); } foreach ((array) $keys as $k) { $this->_client->del($k); } }
/** * Destroy session * * @param string $sessionId * @return boolean */ public function destroy($sessionId) { if (!$this->_useRedis) { return parent::destroy($sessionId); } if ($this->_logLevel >= 7) { Mage::log(sprintf("%s: Destroying ID %s", $this->_getPid(), $sessionId), Zend_Log::DEBUG, self::LOG_FILE); } $this->_redis->pipeline(); if ($this->_dbNum) { $this->_redis->select($this->_dbNum); } $this->_redis->del(self::SESSION_PREFIX . $sessionId); $this->_redis->exec(); return TRUE; }
/** * Destroy session * * @param string $sessionId * @return boolean */ public function destroy($sessionId) { $this->profilerStart(__METHOD__); if ($this->_logLevel >= \Zend_Log::DEBUG) { $this->_log(sprintf("Destroying ID %s", $sessionId)); } $this->_redis->pipeline(); if ($this->_dbNum) { $this->_redis->select($this->_dbNum); } $this->_redis->del(self::SESSION_PREFIX . $sessionId); $this->_redis->exec(); $this->profilerStop(__METHOD__); return TRUE; }
/** * Destroy session * * @param string $sessionId * @return boolean */ public function destroy($sessionId) { if (!$this->_useRedis) { return parent::destroy($sessionId); } Varien_Profiler::start(__METHOD__); if ($this->_logLevel >= Zend_Log::DEBUG) { $this->_log(sprintf("Destroying ID %s", $sessionId)); } $this->_redis->pipeline(); if ($this->_dbNum) { $this->_redis->select($this->_dbNum); } $this->_redis->del(self::SESSION_PREFIX . $sessionId); $this->_redis->exec(); Varien_Profiler::stop(__METHOD__); return TRUE; }
/** * Destroy session * * @param string $sessionId * @return boolean */ public function destroy($sessionId) { $this->_log(sprintf("Destroying ID %s", $sessionId)); $this->_redis->pipeline(); if ($this->_dbNum) { $this->_redis->select($this->_dbNum); } $this->_redis->del(self::SESSION_PREFIX . $sessionId); $this->_redis->exec(); return true; }
/** * Required to pass unit tests * * @param string $id * @return void */ public function ___expire($id) { $this->_redis->del(self::PREFIX_KEY . $id); }