/** * 結果セットを連想配列に変換する * * @param P2KeyValueStore_Codec_Interface $codec * @return array */ public function toArray(P2KeyValueStore_Codec_Interface $codec = null) { if ($codc === null) { $key = $this->arkey; $value = $this->value; } else { $key = $codec->decodeKey($this->arkey); $value = $codec->decodeValue($this->value); } return array('id' => (int) $this->id, 'key' => $key, 'value' => $value, 'mtime' => (int) $this->mtime, 'order' => (int) $this->sort_order); }
/** * 全てのキーの配列を返す * 有効期限切れのレコードを除外したい場合は事前にgc()しておくこと * * @param string $prefix * @param array $orderBy * @param int $limit * @param int $offset * @return array */ public function getKeys($prefix = null, array $orderBy = null, $limit = null, $offset = null) { $query = self::Q_GETKEYS; if ($prefix !== null) { $query .= ' WHERE ' . self::C_KEY_BEGINS; } $query .= $this->buildOrderBy($orderBy); $query .= $this->buildLimit($limit, $offset); $stmt = $this->_prepare($query, true); if ($prefix !== null) { $this->bindValueForPrefixSearch($stmt, $prefix); } $stmt->execute(); $stmt->setFetchMode(PDO::FETCH_COLUMN, 0); $keys = array(); while (($key = $stmt->fetch()) !== false) { $keys[] = $this->_codec->decodeKey($key); } return $keys; }