Exemplo n.º 1
0
 function get_basic_strings($iterations = 20000)
 {
     $result = array();
     for ($i = 0; $i < $iterations; $i++) {
         $key = new Rediska_Key($i);
         $result[] = $key->getValue();
     }
 }
Exemplo n.º 2
0
 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();
 }
Exemplo n.º 3
0
 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);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 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);
 }
Exemplo n.º 6
0
 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;
 }
Exemplo n.º 7
0
 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);
 }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
 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}");
 }
Exemplo n.º 10
0
 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);
 }
Exemplo n.º 11
0
 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;
     }
 }
Exemplo n.º 12
0
    $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;
}
Exemplo n.º 13
0
 public function __get($attribute)
 {
     $value = $this->_key->getValue();
     if (is_null($value)) {
         $value = $this->_object->{$attribute};
         $this->_key->setValue($value);
     }
     return $value;
 }
Exemplo n.º 14
0
 public function get($keyName)
 {
     $key = new Rediska_Key($keyName);
     return $key->getValue();
 }
Exemplo n.º 15
0
 public static function fetchNextId()
 {
     $key = new Rediska_Key('posts:nextId');
     return $key->increment();
 }
Exemplo n.º 16
0
<?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");
Exemplo n.º 17
0
 /**
  * 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();
 }
Exemplo n.º 18
0
 public function delete($key)
 {
     $key = new Rediska_Key($this->prefix . $key);
     return $key->delete();
 }
Exemplo n.º 19
0
 public static function set($keyname, $value = null)
 {
     self::$_keys[$keyname] = $value;
     $key = new Rediska_Key($keyname);
     return $key->setValue($value);
 }
Exemplo n.º 20
0
 public static function setLoginToIdLink($login, $id)
 {
     $key = new Rediska_Key('userIdKey:' . $login);
     $key->setValue($id);
 }
Exemplo n.º 21
0
 public function decrement($key, $val = 1)
 {
     $Key = new Rediska_Key($key);
     $Key->setRediska($this->Rediska);
     return $Key->decrement($val);
 }