예제 #1
0
파일: Redis.php 프로젝트: simon-downes/spf
 /**
  * Refresh the local cache index from the cache.
  * The index is stored in Redis as a set with the key <prefix>::index.
  * Items are added and removed from the index via the write and delete but
  * are also expired automatically by Redis. This function reads the index
  * set and checks the TTL of each key, removing those that no longer exist
  * from the index.
  * @return self
  */
 public function refreshIndex()
 {
     if ($this->indexing) {
         $expired = array();
         foreach ($this->store->sMembers("{$this->prefix}::index") as $k) {
             switch ($this->index[$k] = $this->store->ttl($k)) {
                 case -2:
                     $expired[] = $k;
                     unset($this->index[$k]);
                     break;
                 case -1:
                     // We're not running Redis 2.8 yet so we always get -1
                     // we'll assume all keys have an expiry and remove any without in order to keep the index clean
                     //$this->index[$k] = 2147483648;
                     $expired[] = $k;
                     unset($this->index[$k]);
                     break;
                 default:
                     $this->index[$k] = time() + $this->index[$k];
             }
         }
         foreach ($expired as $k) {
             $this->removeFromIndex($k);
         }
     }
     return $this;
 }
예제 #2
0
 /**
  * {@inheritdoc}
  * Example:
  * <code>
  * //Does Andres have access to the customers resource to create?
  * $acl->isAllowed('Andres', 'Products', 'create');
  * //Do guests have access to any resource to edit?
  * $acl->isAllowed('guests', '*', 'edit');
  * </code>
  *
  * @param string $role
  * @param string $resource
  * @param string $access
  *
  * @return bool
  */
 public function isAllowed($role, $resource, $access)
 {
     if ($this->redis->sIsMember("accessList:{$role}:{$resource}:" . Acl::ALLOW, $access)) {
         return Acl::ALLOW;
     }
     if ($this->redis->exists("rolesInherits:{$role}")) {
         $rolesInherits = $this->redis->sMembers("rolesInherits:{$role}");
         foreach ($rolesInherits as $role) {
             if ($this->redis->sIsMember("accessList:{$role}:{$resource}:" . Acl::ALLOW, $access)) {
                 return Acl::ALLOW;
             }
         }
     }
     /**
      * Return the default access action
      */
     return $this->getDefaultAction();
 }
예제 #3
0
 /**
  * @param $key
  * @return mixed
  */
 public function getListItems($key)
 {
     return $this->client->sMembers($key);
 }