lithium\storage\cache\adapter\Redis::read PHP 메소드

read() 공개 메소드

Read values from the cache. Will attempt to return an array of data containing key/value pairs of the requested data.
public read ( array $keys ) : array
$keys array Keys to uniquely identify the cached items.
리턴 array Cached values keyed by cache keys on successful read, keys which could not be read will not be included in the results array.
    public function read(array $keys)
    {
        if (count($keys) > 1) {
            $results = array();
            $data = $this->connection->mGet($keys);
            foreach ($data as $key => $item) {
                $key = $keys[$key];
                if ($item === false && !$connection->exists($key)) {
                    continue;
                }
                $results[$key] = $item;
            }
            return $results;
        }
        $result = $this->connection->get($key = current($keys));
        return $result === false ? array() : array($key => $result);
    }

Usage Example

예제 #1
0
 public function testReadWithScope()
 {
     $adapter = new Redis(array('scope' => 'primary'));
     $this->_redis->set('primary:key1', 'test1', 60);
     $this->_redis->set('key1', 'test2', 60);
     $keys = array('key1');
     $expected = array('key1' => 'test1');
     $result = $adapter->read($keys);
     $this->assertEqual($expected, $result);
 }