Skip to content

Commit

Permalink
Simplify.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Balogh committed Oct 15, 2014
1 parent 97e67e9 commit 74b058e
Show file tree
Hide file tree
Showing 16 changed files with 275 additions and 1,080 deletions.
110 changes: 19 additions & 91 deletions readme.md
Expand Up @@ -60,16 +60,21 @@ $kvs = new KeyValueStore($adapter);

$kvs->set('sample_key', 'Sample value');
$kvs->get('sample_key');
$kvs->delete('sample_key');
```

**To see other specific examples please visit the links in the [Adapters](https://github.com/adammbalogh/key-value-store#adapters) section.**

# API

You can call all of the API methods on a instance of ```KeyValueStore```.

## Key

```php
/**
* Removes a key.
*
* @param string $key
*
* @return bool True if the deletion was successful, false if the deletion was unsuccessful.
Expand All @@ -80,6 +85,8 @@ $kvs->get('sample_key');
public function delete($key);

/**
* Sets a key's time to live in seconds.
*
* @param string $key
* @param int $seconds
*
Expand All @@ -90,19 +97,12 @@ public function delete($key);
*/
public function expire($key, $seconds);

/**
* @return array
*
* @throws InternalException
*/
public function getKeys();

/**
* Returns the remaining time to live of a key that has a timeout.
*
* @param string $key
*
* @return int Ttl in seconds
* @return int Ttl in seconds.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
Expand All @@ -111,6 +111,8 @@ public function getKeys();
public function getTtl($key);

/**
* Determines if a key exists.
*
* @param string $key
*
* @return bool True if the key does exist, false if the key does not exist.
Expand All @@ -121,7 +123,7 @@ public function getTtl($key);
public function has($key);

/**
* Remove the existing timeout on key, turning the key from volatile (a key with an expire set)
* Removes 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
Expand All @@ -134,48 +136,15 @@ public function has($key);
public function persist($key);
```

## String
## Value

```php
/**
* @param string $key
* @param string $value
*
* @return int The length of the string after the append operation.
* Gets the value of a key.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function append($key, $value);

/**
* @param string $key
*
* @return int The value of key after the decrement
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function decrement($key);

/**
* @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);

/**
* @param string $key
*
* @return string The value of the key
* @return mixed The value of the key.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
Expand All @@ -184,66 +153,25 @@ public function decrementBy($key, $decrement);
public function get($key);

/**
* @param string $key
*
* @return int
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function getValueLength($key);

/**
* @param string $key
*
* @return int The value of key after the increment
* Sets the value of a key.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function increment($key);

/**
* @param string $key
* @param int $increment
* @param mixed $value Can be any of serializable data type.
*
* @return int The value of key after the increment
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
* @throws InternalException
*/
public function incrementBy($key, $increment);

/**
* @param string $key
* @param string $value
*
* @return bool True if the set was successful, false if it was unsuccessful
* @return bool True if the set was successful, false if it was unsuccessful.
*
* @throws \InvalidArgumentException
* @throws InternalException
*/
public function 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 InternalException
*/
public function setIfNotExists($key, $value);
```

## Server

```php
/**
* Removes all keys.
*
* @return void
*
* @throws \AdammBalogh\KeyValueStore\Exception\InternalException
Expand Down
12 changes: 12 additions & 0 deletions src/Adapter/Util.php
Expand Up @@ -68,4 +68,16 @@ public static function checkArgInteger($argument)
throw new \InvalidArgumentException();
}
}

/**
* @param mixed $argument
*
* @throws \InvalidArgumentException
*/
public static function checkArgSerializable($argument)
{
if (is_resource($argument)) {
throw new \InvalidArgumentException();
}
}
}
2 changes: 1 addition & 1 deletion src/Contract/AdapterInterface.php
@@ -1,6 +1,6 @@
<?php namespace AdammBalogh\KeyValueStore\Contract;

interface AdapterInterface extends KeyInterface, StringInterface, ServerInterface
interface AdapterInterface extends KeyInterface, ValueInterface, ServerInterface
{
/**
* @return AdapterInterface
Expand Down
17 changes: 8 additions & 9 deletions src/Contract/KeyInterface.php
Expand Up @@ -6,6 +6,8 @@
interface KeyInterface
{
/**
* Removes a key.
*
* @param string $key
*
* @return bool True if the deletion was successful, false if the deletion was unsuccessful.
Expand All @@ -16,6 +18,8 @@ interface KeyInterface
public function delete($key);

/**
* Sets a key's time to live in seconds.
*
* @param string $key
* @param int $seconds
*
Expand All @@ -26,19 +30,12 @@ public function delete($key);
*/
public function expire($key, $seconds);

/**
* @return array
*
* @throws InternalException
*/
public function getKeys();

/**
* Returns the remaining time to live of a key that has a timeout.
*
* @param string $key
*
* @return int Ttl in seconds
* @return int Ttl in seconds.
*
* @throws \InvalidArgumentException
* @throws KeyNotFoundException
Expand All @@ -47,6 +44,8 @@ public function getKeys();
public function getTtl($key);

/**
* Determines if a key exists.
*
* @param string $key
*
* @return bool True if the key does exist, false if the key does not exist.
Expand All @@ -57,7 +56,7 @@ public function getTtl($key);
public function has($key);

/**
* Remove the existing timeout on key, turning the key from volatile (a key with an expire set)
* Removes 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
Expand Down
2 changes: 2 additions & 0 deletions src/Contract/ServerInterface.php
Expand Up @@ -3,6 +3,8 @@
interface ServerInterface
{
/**
* Removes all keys.
*
* @return void
*
* @throws \AdammBalogh\KeyValueStore\Exception\InternalException
Expand Down
109 changes: 0 additions & 109 deletions src/Contract/StringInterface.php

This file was deleted.

0 comments on commit 74b058e

Please sign in to comment.