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 static function get($keyname) { if (empty(self::$_keys[$keyname])) { $key = new Rediska_Key($keyname); self::$_keys[$keyname] = $key->getValue(); } return self::$_keys[$keyname]; }
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 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 get($key) { $Key = new Rediska_Key($key); $Key->setRediska($this->Rediska); if (!$Key->isExists()) { return false; } // try { // return $Key->getValue(); // } catch (Exception $exc) { // prd($key); // echo $exc->getTraceAsString(); // } # @todo #$Key->delete(); return $Key->getValue(); }
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; } }
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(); }
/** * 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 fetch($key, $unserialize = false) { $cacheID = $this->prefix . $key; $key = new Rediska_Key($cacheID); $value = $key->getValue(); if ($this->isSerialize or $unserialize) { $value = unserialize($value); } return $value; }
$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; }