diff --git a/readme.md b/readme.md index 9120be6..ca03ce9 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,11 @@ # Key-Value Store by [@adammbalogh](http://twitter.com/adammbalogh) [![Build Status](https://img.shields.io/travis/adammbalogh/key-value-store/master.svg?style=flat)](https://travis-ci.org/adammbalogh/key-value-store) +[![Quality Score](https://img.shields.io/scrutinizer/g/adammbalogh/key-value-store.svg?style=flat)](https://scrutinizer-ci.com/g/adammbalogh/key-value-store) [![Software License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat)](LICENSE) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/f1ddb443-d2a1-499a-926a-060cdecd4100/small.png)](https://insight.sensiolabs.com/projects/f1ddb443-d2a1-499a-926a-060cdecd4100) + +# Support + +[![Support with Gittip](http://img.shields.io/gittip/adammbalogh.svg?style=flat)](https://www.gittip.com/adammbalogh/) diff --git a/src/Adapter/AbstractAdapter.php b/src/Adapter/AbstractAdapter.php new file mode 100644 index 0000000..abf85b2 --- /dev/null +++ b/src/Adapter/AbstractAdapter.php @@ -0,0 +1,14 @@ +client; + } +} diff --git a/src/Adapter/NullAdapter/KeyTrait.php b/src/Adapter/NullAdapter/KeyTrait.php new file mode 100644 index 0000000..35a3ce5 --- /dev/null +++ b/src/Adapter/NullAdapter/KeyTrait.php @@ -0,0 +1,104 @@ +adapter->delete($key); } + /** + * @param string $key + * @param int $seconds + * + * @return bool True if the timeout was set, false if the timeout could not be set. + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + */ public function expire($key, $seconds) { $this->adapter->expire($key, $seconds); } + /** + * @param string $key + * @param int $timestamp + * + * @return bool True if the timeout was set, false if the timeout could not be set. + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + */ public function expireAt($key, $timestamp) { $this->adapter->expireAt($key, $timestamp); } + /** + * @return array + */ public function getKeys() { $this->adapter->getKeys(); } + /** + * Returns the remaining time to live of a key that has a timeout. + * + * @param string $key + * + * @return int Ttl in seconds + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException If the key exists but has no associated expire. + */ public function getTtl($key) { $this->adapter->getTtl($key); } + /** + * @param string $key + * + * @return bool True if the key does exist, false if the key does not exist. + * + * @throws \InvalidArgumentException + */ public function has($key) { $this->adapter->has($key); } + /** + * Remove the existing timeout on key, turning the key from volatile (a key with an expire set) + * to persistent (a key that will never expire as no timeout is associated). + * + * @param string $key + * + * @return bool True if the persist was success, false if the persis was unsuccessful. + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + */ public function persist($key) { $this->adapter->persist($key); diff --git a/src/Implementation/StringTrait.php b/src/Implementation/StringTrait.php index 8a32175..4a9e984 100644 --- a/src/Implementation/StringTrait.php +++ b/src/Implementation/StringTrait.php @@ -1,47 +1,136 @@ adapter->append($key, $value); } - public function decr($key) + /** + * @param string $key + * + * @return int The value of key after the decrement + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException + */ + public function decrement($key) { - $this->adapter->decr($key); + $this->adapter->decrement($key); } - public function decrBy($key, $decrement) + /** + * @param string $key + * @param int $decrement + * + * @return int The value of key after the decrement + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException + */ + public function decrementBy($key, $decrement) { - $this->adapter->decrBy($key, $decrement); + $this->adapter->decrementBy($key, $decrement); } + /** + * @param string $key + * + * @return string The value of the key + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException + */ public function get($key) { $this->adapter->get($key); } + /** + * @param string $key + * + * @return int + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException + */ public function getValueLength($key) { $this->adapter->getValueLength($key); } - public function incr($key) + /** + * @param string $key + * + * @return int The value of key after the increment + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException + */ + public function increment($key) { - $this->adapter->incr($key); + $this->adapter->increment($key); } - public function incrBy($key, $increment) + /** + * @param string $key + * @param int $increment + * + * @return int The value of key after the increment + * + * @throws \InvalidArgumentException + * @throws KeyNotFoundException + * @throws InternalException + */ + public function incrementBy($key, $increment) { - $this->adapter->incrBy($key, $increment); + $this->adapter->incrementBy($key, $increment); } + /** + * @param string $key + * @param string $value + * + * @return bool True if the set was successful, false if it was unsuccessful + * + * @throws \InvalidArgumentException + */ public function set($key, $value) { $this->adapter->set($key, $value); } + /** + * @param string $key + * @param string $value + * + * @return bool True if the set was successful, false if it was unsuccessful + * + * @throws \InvalidArgumentException + * @throws KeyAlreadyExistsException + */ public function setIfNotExists($key, $value) { $this->adapter->setIfNotExists($key, $value); diff --git a/src/KeyValueStore.php b/src/KeyValueStore.php index 87cc8b7..58b43f3 100644 --- a/src/KeyValueStore.php +++ b/src/KeyValueStore.php @@ -2,10 +2,12 @@ use AdammBalogh\KeyValueStore\Contract\AdapterInterface; use AdammBalogh\KeyValueStore\Implementation\AdapterTrait; +use AdammBalogh\KeyValueStore\Implementation\KeyTrait; +use AdammBalogh\KeyValueStore\Implementation\StringTrait; class KeyValueStore implements AdapterInterface { - use AdapterTrait; + use AdapterTrait, KeyTrait, StringTrait; /** * @param AdapterInterface $adapter