function get_basic_strings($iterations = 20000) { $result = array(); for ($i = 0; $i < $iterations; $i++) { $key = new Rediska_Key($i); $result[] = $key->getValue(); } }
function actionTest() { $options = array('servers' => array(array('host' => '127.0.0.1', 'port' => 6379))); E_FW::load_File('helper_Rediska_Rediska'); $rediska = new Rediska($options); $key = new Rediska_Key('mykey'); //$key->setValue('value'); echo $key->getValue(); }
public function write($id, $data) { // get the default session max lifetime $ttl = ini_get("session.gc_maxlifetime"); // use Redis' setex command to set the key value and its expire // time $cmd = new Rediska_Key($id); // the session string is base64 encoded before being stored return (bool) $cmd->SetAndExpire(base64_encode($data), $ttl); }
public function testSetExpireOnConstruct() { $key = new Rediska_Key('test', 2); $reply = $key->setValue(123); $this->assertTrue($reply); $value = $key->getValue(); $this->assertEquals(123, $value); sleep(3); $value = $key->getValue(); $this->assertNull($value); }
public function testSpecifiedServerAlias() { $this->_addServerOrSkipTest(REDISKA_SECOND_HOST, REDISKA_SECOND_PORT); $key1 = new Rediska_Key('test', null, REDISKA_HOST . ':' . REDISKA_PORT); $key1->setValue(1); $key2 = new Rediska_Key('test', null, REDISKA_SECOND_HOST . ':' . REDISKA_SECOND_PORT); $key2->setValue(2); $reply = $this->rediska->on(REDISKA_HOST . ':' . REDISKA_PORT)->get('test'); $this->assertEquals(1, $reply); $reply = $this->rediska->on(REDISKA_SECOND_HOST . ':' . REDISKA_SECOND_PORT)->get('test'); $this->assertEquals(2, $reply); }
public function setnx($keyName, $expire, $value = '') { $command = new \Rediska_Command_Set($this->client, 'Set', array($keyName, $value, false)); try { if (!$command->execute()) { return false; } $key = new \Rediska_Key($keyName); $key->expire($expire); } catch (\Rediska_Exception $e) { throw new \VisitCounter\Exception\RedisException($e->getMessage(), 0, $e); } return true; }
public function testGetLifetime() { $this->key->getRediska()->set($this->key->getName(), 1); $this->key->getRediska()->expire($this->key->getName(), 50); $reply = $this->key->getLifetime(); $this->assertGreaterThan(45, $reply); }
public function testOffsetUnset() { $this->rediska->setBit($this->key->getName(), 1, 1); $reply = $this->rediska->getBit($this->key->getName(), 1); $this->assertEquals(1, $reply); unset($this->key[1]); $reply = $this->rediska->getBit($this->key->getName(), 1); $this->assertEquals(0, $reply); }
public function testGetOrSetValue() { $provider = new BasicKeyDataProvider(); $value = $this->key->getOrSetValue($provider)->data; $this->assertEquals(123, $value); $reply = $this->key->isExists(); $this->assertTrue($reply); $this->assertEquals(123, $this->key->getValue()); $value = $this->key->getOrSetValue($provider)->getOtherDataForTest(); $this->assertEquals(123, $value); $this->key->delete(); $value = $this->key->getOrSetValue($provider)->getData(); $this->assertEquals(123, $value); $reply = $this->key->isExists(); $this->assertTrue($reply); $this->assertEquals(123, $this->key->getValue()); $getOrSetValueObject = $this->key->getOrSetValue($provider); $this->assertEquals(123, "{$getOrSetValueObject}"); }
public function testSetExpireTimestamp() { $time = time() + 1; $this->key->setExpire($time, true); $expire = $this->key->getExpire(); $this->assertEquals($time, $expire); $this->assertTrue($this->key->isExpireTimestamp()); $this->key->setValue(1); sleep(2); $reply = $this->key->getRediska()->get($this->key->getName()); $this->assertNull($reply); }
static function getAll() { $key = new Rediska_Key("allEnglish"); //var_dump($key->getValue()); if ($allenglish = $key->getValue()) { //echo "from redis"; return $allenglish; } else { $mysqli = DB::getConn(); $sql = "select * from english"; $result = DB::getResult($sql, $mysqli); $arr = array(); while ($array = $result->fetch_assoc()) { $arr[] = $array; } $key->setValue($arr); $key->expire(60 * 60); DB::close($mysqli, null, $result); //echo "from db"; return $arr; } }
$key = new Rediska_Key($keyName); $keyValue = "value_{$i}" . "_first"; echo "<br/>"; $key->setValue($keyValue); print "key:{$keyName}" . " value:" . $key->getValue(); #=> value } # $rediska->addServer('192.168.122.10', 6379); $rediska->addServer('10.8.8.10', 6379); $connection = $rediska->getConnectionByAlias('0'); # $rediska->slaveOf($connection); $rediska->removeServer($connection); echo "<br/>"; echo "<br/>"; echo "follow add 10.8.8.10 and delete 6380"; echo "<br/>"; for ($i = 0; $i < 10; $i++) { $keyName = "key{$i}"; $key = new Rediska_Key($keyName); $keyValue = "value_{$i}" . "_second"; echo "<br/>"; $oldValue = $key->getValue(); $key->setValue($keyValue); print "key:{$keyName}" . " value:" . $key->getValue() . " old value:{$oldValue}"; } // Initialize Set with name 'setKeyName' and specified Rediska instance $set = new Rediska_Key_Set('setKeyName', array('rediska' => $rediska)); // Print all elements foreach ($set as $element) { print $element; }
public function __get($attribute) { $value = $this->_key->getValue(); if (is_null($value)) { $value = $this->_object->{$attribute}; $this->_key->setValue($value); } return $value; }
public function get($keyName) { $key = new Rediska_Key($keyName); return $key->getValue(); }
public static function fetchNextId() { $key = new Rediska_Key('posts:nextId'); return $key->increment(); }
<?php require_once '/vagrant_data/data/rediska/library/Rediska.php'; // Initialize Rediska $options = array('namespace' => 'Cache_', 'name' => 'cache'); $rediska = new Rediska($options); $rediska = Rediska_Manager::get('default'); print $rediska->getName(); #=> cache $keyName = "key0"; $key = new Rediska_Key($keyName); $key->setValue("zzzzzzzzzzzzz");
/** * Returns the id of the user to which the selected UUID belongs. If selected UUID does not exist, an * exception with code self::ERROR_NOTFOUND_UUID will be thrown. */ public static function getIdForUuid(&$application, $uuid) { // uuid must be valid if (!ApplicationModel_User::validateUuid($uuid)) { throw new ApplicationModelException_File('UUID is invalid.', self::ERROR_INVALID_UUID); } // use id lookup key $userUuidKey = new Rediska_Key('user_uuid_' . $uuid); if ($userUuidKey->getValue() === null) { throw new ApplicationModelException_File('UUID is invalid.', self::ERROR_NOTFOUND_UUID); } return $userUuidKey->getValue(); }
public function delete($key) { $key = new Rediska_Key($this->prefix . $key); return $key->delete(); }
public static function set($keyname, $value = null) { self::$_keys[$keyname] = $value; $key = new Rediska_Key($keyname); return $key->setValue($value); }
public static function setLoginToIdLink($login, $id) { $key = new Rediska_Key('userIdKey:' . $login); $key->setValue($id); }
public function decrement($key, $val = 1) { $Key = new Rediska_Key($key); $Key->setRediska($this->Rediska); return $Key->decrement($val); }