Exemple #1
0
 public function testSetValue()
 {
     $reply = $this->key->setValue(123);
     $this->assertTrue($reply);
     $value = $this->key->getRediska()->get($this->key->getName());
     $this->assertEquals(123, $value);
 }
Exemple #2
0
 public function testAppend()
 {
     $this->key->setValue('abc');
     $reply = $this->key->append('abc');
     $this->assertEquals(6, $reply);
     $reply = $this->key->getRediska()->get($this->key->getName());
     $this->assertEquals('abcabc', $reply);
 }
 function set_basic_strings($iterations = 20000)
 {
     for ($i = 0; $i < $iterations; $i++) {
         $key = new Rediska_Key($i);
         $key->setValue($i);
     }
 }
Exemple #4
0
 public function set($key, $val, $ttl = 0)
 {
     if ($ttl === 0) {
         $ttl = null;
     }
     $Key = new Rediska_Key($key, array('expire' => $ttl));
     $Key->setRediska($this->Rediska);
     return $Key->setValue($val);
 }
Exemple #5
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);
 }
 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);
 }
Exemple #7
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);
 }
Exemple #8
0
 public function testSpecifiedServerAlias()
 {
     $this->_addSecondServerOrSkipTest();
     list($firstServer, $secondServer) = $this->rediska->getConnections();
     $key1 = new Rediska_Key('test', array('serverAlias' => $firstServer));
     $key1->setValue(1);
     $key2 = new Rediska_Key('test', array('serverAlias' => $secondServer));
     $key2->setValue(2);
     $reply = $this->rediska->on($firstServer->getAlias())->get('test');
     $this->assertEquals(1, $reply);
     $reply = $this->rediska->on($secondServer->getAlias())->get('test');
     $this->assertEquals(2, $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;
     }
 }
Exemple #10
0
 public function __get($attribute)
 {
     $value = $this->_key->getValue();
     if (is_null($value)) {
         $value = $this->_object->{$attribute};
         $this->_key->setValue($value);
     }
     return $value;
 }
Exemple #11
0
 public function set($keyName, $keyValue)
 {
     $key = new Rediska_Key($keyName);
     $key->setValue($keyValue);
 }
Exemple #12
0
 /**
  * Saves user's information into the database. If user's id is not known, it will try to create a new user.
  * If user's id is known, it will try to edit information in database to make it identical to information in
  * this class. If you want to change user's login, load user's information before doing so. If the user with
  * selected id does not exist, it will throw an exception with code self::ERROR_NOTFOUND_ID. If the function
  * tries to create a user with taken login, an exception with code self::ERROR_TAKEN_LOGIN will be thrown.
  * If the user tries to take somebody else's UUID, an exception with code self::ERROR_TAKEN_UUID will be
  * thrown.
  */
 public function save()
 {
     // id lookup key
     $userLoginKey = new Rediska_Key('user_login_' . $this->login);
     // id is known - we are going to edit user's information
     if ($this->id !== null) {
         // user with selected id must exist
         if (!$this->application->rediska->exists('user_' . $this->id)) {
             throw new ApplicationModelException_User('User with id ' . $this->id . ' does not exist in the database.', self::ERROR_NOTFOUND_ID);
         }
     } else {
         // new login must not be taken by someone else
         if ($userLoginKey->getValue() !== null) {
             throw new ApplicationModelException_User('User with login ' . $this->login . ' already exists in the database.', self::ERROR_TAKEN_LOGIN);
         }
     }
     // make sure that the user does not want to take somebody else's uuid
     foreach ($this->uuids as $time => $uuid) {
         $userUuidKey = new Rediska_Key('user_uuid_' . $uuid);
         if ($userUuidKey->getValue() !== null && $userUuidKey->getValue() != $this->id) {
             throw new ApplicationModelException_User('UUID ' . $uuid . ' is taken by somebody else.', self::ERROR_TAKEN_UUID);
         }
     }
     // if we are creating a new user - get the new id for him
     if ($this->id === null) {
         $this->id = $this->incrementRedisCounter('users_count');
     }
     // if user's login needs to be changed (for new users, this will not be active)
     if ($this->loginOld !== null && $this->loginOld != $this->login) {
         // new login must not be taken by someone else
         if ($userLoginKey->getValue() !== null) {
             throw new ApplicationModelException_User('User with login ' . $this->login . ' already exists in the database.', self::ERROR_TAKEN_LOGIN);
         }
         // remove old id lookup key
         $userLoginOldKey = new Rediska_Key('user_login_' . $this->loginOld);
         $userLoginOldKey->delete();
     }
     // save user's login and password hash
     $userKeyHash = new Rediska_Key_Hash('user_' . $this->id);
     $userKeyHash->login = $this->login;
     $this->loginOld = $this->login;
     $userKeyHash->password = $this->passwordHash;
     // save id lookup key
     $userLoginKey->setValue($this->id);
     // for every old uuid of the user:
     $uuidsKeySet = new Rediska_Key_SortedSet('user_' . $this->id . '_uuids');
     foreach ($uuidsKeySet as $uuid) {
         // cut off uuid_ prefix
         $uuid = substr($uuid, strlen('uuid_'));
         // remove old id lookup key
         $userUuidOldKey = new Rediska_Key('user_uuid_' . $uuid);
         $userUuidOldKey->delete();
         // remove uuid from the list
         $uuidsKeySet->remove('uuid_' . $uuid);
     }
     // for every new uuid for this user:
     foreach ($this->uuids as $time => $uuid) {
         // create a new id lookup key
         $userUuidKey = new Rediska_Key('user_uuid_' . $uuid);
         $userUuidKey->setValue($this->id);
         // add it to the list
         $uuidsKeySet[$time] = 'uuid_' . $uuid;
     }
 }
Exemple #13
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;
}
Exemple #14
0
 public static function set($keyname, $value = null)
 {
     self::$_keys[$keyname] = $value;
     $key = new Rediska_Key($keyname);
     return $key->setValue($value);
 }
Exemple #15
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");
Exemple #16
0
 public static function setLoginToIdLink($login, $id)
 {
     $key = new Rediska_Key('userIdKey:' . $login);
     $key->setValue($id);
 }
Exemple #17
0
 public function store($key, $cacheData, $parSet = array())
 {
     $params = array('expireTime' => $this->expireTime, 'serialize' => false);
     foreach ($parSet as $k => $v) {
         $params[$k] = $v;
     }
     $key = new Rediska_Key($this->prefix . $key);
     $key->setExpire($params['expireTime']);
     if ($this->isSerialize or $params['serialize']) {
         $cacheData = serialize($cacheData);
     }
     return $key->setValue($cacheData);
 }