コード例 #1
0
 function get_basic_strings($iterations = 20000)
 {
     $result = array();
     for ($i = 0; $i < $iterations; $i++) {
         $key = new Rediska_Key($i);
         $result[] = $key->getValue();
     }
 }
コード例 #2
0
ファイル: Test.php プロジェクト: eason007/e-fw
 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();
 }
コード例 #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);
 }
コード例 #4
0
ファイル: Basic.php プロジェクト: utachkin/Rediska
 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);
 }
コード例 #5
0
ファイル: Abstract.php プロジェクト: utachkin/Rediska
 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);
 }
コード例 #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;
 }
コード例 #7
0
ファイル: AbstractTest.php プロジェクト: r-kovalenko/Rediska
 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);
 }
コード例 #8
0
ファイル: KeyTest.php プロジェクト: r-kovalenko/Rediska
 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);
 }
コード例 #9
0
ファイル: KeyTest.php プロジェクト: grenzr/sfRediskaPlugin
 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}");
 }
コード例 #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);
 }
コード例 #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;
     }
 }
コード例 #12
0
ファイル: index2.php プロジェクト: kanglanglang/popkit
    $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;
}
コード例 #13
0
ファイル: Key.php プロジェクト: r-kovalenko/Rediska
 public function __get($attribute)
 {
     $value = $this->_key->getValue();
     if (is_null($value)) {
         $value = $this->_object->{$attribute};
         $this->_key->setValue($value);
     }
     return $value;
 }
コード例 #14
0
ファイル: dredis.php プロジェクト: kanglanglang/popkit
 public function get($keyName)
 {
     $key = new Rediska_Key($keyName);
     return $key->getValue();
 }
コード例 #15
0
ファイル: Post.php プロジェクト: r-kovalenko/Rediska
 public static function fetchNextId()
 {
     $key = new Rediska_Key('posts:nextId');
     return $key->increment();
 }
コード例 #16
0
ファイル: hello.php プロジェクト: kanglanglang/popkit
<?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");
コード例 #17
0
ファイル: User.php プロジェクト: tanya61612/Pastexen
 /**
  * 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();
 }
コード例 #18
0
ファイル: Core.php プロジェクト: eason007/e-fw
 public function delete($key)
 {
     $key = new Rediska_Key($this->prefix . $key);
     return $key->delete();
 }
コード例 #19
0
ファイル: Redis.php プロジェクト: beejhuff/Bouncer
 public static function set($keyname, $value = null)
 {
     self::$_keys[$keyname] = $value;
     $key = new Rediska_Key($keyname);
     return $key->setValue($value);
 }
コード例 #20
0
ファイル: User.php プロジェクト: grenzr/sfRediskaPlugin
 public static function setLoginToIdLink($login, $id)
 {
     $key = new Rediska_Key('userIdKey:' . $login);
     $key->setValue($id);
 }
コード例 #21
0
ファイル: Redis.php プロジェクト: kvz/eventcache
 public function decrement($key, $val = 1)
 {
     $Key = new Rediska_Key($key);
     $Key->setRediska($this->Rediska);
     return $Key->decrement($val);
 }