예제 #1
0
 public function release()
 {
     $result = 1;
     try {
         if ($this->has_lock()) {
             $redis = mr_bootstrap::redis();
             if (empty($this->timetolive)) {
                 $result = $redis->delete($this->uniquekey);
             } else {
                 $timetolive = $this->parse_timetolive($redis->get($this->uniquekey));
                 // We check to value to make sure the key hasn't expired and been re-acquired by another process
                 if ($timetolive == $this->timetolive and $timetolive > time()) {
                     $result = $redis->delete($this->uniquekey);
                 }
             }
             $redis->close();
         }
     } catch (RedisException $e) {
         debugging("RedisException caught on host {$this->get_hostname()} with message: {$e->getMessage()}");
     } catch (Exception $e) {
         debugging("Exception caught on host {$this->get_hostname()} with message: {$e->getMessage()}");
     }
     $this->set_lockacquired(false);
     return $result == 1;
 }
예제 #2
0
 public function test_redis_set_get_delete()
 {
     $redis = mr_bootstrap::redis();
     $this->assertTrue($redis->set('simpletest', 'foo'));
     $this->assertEqual($redis->get('simpletest'), 'foo');
     $this->assertEqual($redis->delete('simpletest'), 1);
     $this->assertTrue($redis->close());
 }