Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finalized interfaces, nulladapter, exceptions
- Loading branch information
Adam Balogh
committed
Sep 22, 2014
1 parent
1b6cdb0
commit 814ad55
Showing
14 changed files
with
613 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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/) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php namespace AdammBalogh\KeyValueStore\Adapter; | ||
|
||
use AdammBalogh\KeyValueStore\Contract\AdapterInterface; | ||
|
||
abstract class AbstractAdapter implements AdapterInterface | ||
{ | ||
/** | ||
* @return $this | ||
*/ | ||
public function getAdapter() | ||
{ | ||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php namespace AdammBalogh\KeyValueStore\Adapter; | ||
|
||
class NullAdapter extends AbstractAdapter | ||
{ | ||
use NullAdapter\ClientTrait, NullAdapter\KeyTrait, NullAdapter\StringTrait; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php namespace AdammBalogh\KeyValueStore\Adapter\NullAdapter; | ||
|
||
trait ClientTrait | ||
{ | ||
/** | ||
* @var null | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @return null | ||
*/ | ||
public function getClient() | ||
{ | ||
return $this->client; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php namespace AdammBalogh\KeyValueStore\Adapter\NullAdapter; | ||
|
||
use AdammBalogh\KeyValueStore\Exception\KeyNotFoundException; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
trait KeyTrait | ||
{ | ||
use ClientTrait; | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return bool True if the deletion was successful, false if it was unsuccessful. | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
*/ | ||
public function delete($key) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @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) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @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) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getKeys() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* 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) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return bool True if the key does exist, false if the key does not exist. | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function has($key) | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* 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) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
<?php namespace AdammBalogh\KeyValueStore\Adapter\NullAdapter; | ||
|
||
use AdammBalogh\KeyValueStore\Exception\InternalException; | ||
use AdammBalogh\KeyValueStore\Exception\KeyAlreadyExistsException; | ||
use AdammBalogh\KeyValueStore\Exception\KeyNotFoundException; | ||
|
||
/** | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
trait StringTrait | ||
{ | ||
use ClientTrait; | ||
|
||
/** | ||
* @param string $key | ||
* @param string $value | ||
* | ||
* @return int The length of the string after the append operation. | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
* @throws InternalException | ||
*/ | ||
public function append($key, $value) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return int The value of key after the decrement | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
* @throws InternalException | ||
*/ | ||
public function decrement($key) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @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) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return string The value of the key | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
* @throws InternalException | ||
*/ | ||
public function get($key) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return int | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
* @throws InternalException | ||
*/ | ||
public function getValueLength($key) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return int The value of key after the increment | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
* @throws InternalException | ||
*/ | ||
public function increment($key) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @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) | ||
{ | ||
throw new KeyNotFoundException(); | ||
} | ||
|
||
/** | ||
* @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) | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @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) | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,79 @@ | ||
<?php namespace AdammBalogh\KeyValueStore\Contract; | ||
|
||
use AdammBalogh\KeyValueStore\Exception\InternalException; | ||
use AdammBalogh\KeyValueStore\Exception\KeyNotFoundException; | ||
|
||
interface KeyInterface | ||
{ | ||
/** | ||
* @param string $key | ||
* | ||
* @return bool True if the deletion was successful, false if it was unsuccessful. | ||
* | ||
* @throws \InvalidArgumentException | ||
* @throws KeyNotFoundException | ||
*/ | ||
public function 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); | ||
|
||
/** | ||
* @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); | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function 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); | ||
|
||
/** | ||
* @param string $key | ||
* | ||
* @return bool True if the key does exist, false if the key does not exist. | ||
* | ||
* @throws \InvalidArgumentException | ||
*/ | ||
public function 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); | ||
} |
Oops, something went wrong.