Skip to content

Commit

Permalink
Merge pull request #245 from DeryabinSergey/some-fixes
Browse files Browse the repository at this point in the history
Some fixes
  • Loading branch information
sugrob authored May 21, 2020
2 parents 57684d2 + b0c50f5 commit e82cc8c
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 128 deletions.
4 changes: 2 additions & 2 deletions src/Core/Cache/BaseAggregateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function doAddPeer($label, CachePeer $peer)
* low-level cache access
**/

public function increment($key, $value)
public function increment($key, int $value = 1)
{
$label = $this->guessLabel($key);

Expand All @@ -97,7 +97,7 @@ public function increment($key, $value)
return null;
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
$label = $this->guessLabel($key);

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/CachePeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ abstract class CachePeer
abstract public function get($key);
abstract public function delete($key);

abstract public function increment($key, $value);
abstract public function decrement($key, $value);
abstract public function increment($key, int $value = 1);
abstract public function decrement($key, int $value = 1);

abstract protected function store(
$action, $key, $value, $expires = Cache::EXPIRES_MEDIUM
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/DebugCachePeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function mark($className)
return $this;
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
$beginTime = microtime(true);
$value = $this->peer->increment($key, $value);
Expand All @@ -112,7 +112,7 @@ public function increment($key, $value)
return $value;
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
$beginTime = microtime(true);
$value = $this->peer->decrement($key, $value);
Expand Down
13 changes: 9 additions & 4 deletions src/Core/Cache/PeclMemcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function clean()
return parent::clean();
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
try {
return $this->instance->increment($key, $value);
Expand All @@ -94,7 +94,7 @@ public function increment($key, $value)
}
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
try {
return $this->instance->decrement($key, $value);
Expand All @@ -108,13 +108,18 @@ public function getList($indexes)
return
($return = $this->get($indexes))
? $return
: array();
: null;
}

public function get($index)
{
$flag = null;
try {
return $this->instance->get($index);
$result = $this->instance->get($index, $flag);
return
$result === false && is_null($flag)
? null
: $result;
} catch (BaseException $e) {
if(strpos($e->getMessage(), 'Invalid key') !== false)
return null;
Expand Down
12 changes: 6 additions & 6 deletions src/Core/Cache/PeclMemcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ public function __construct(
if ($connectTimeout != self::DEFAULT_CONNECT_TIMEOUT) {
$this->instance->setOption(\Memcached::OPT_CONNECT_TIMEOUT, $connectTimeout);
}

if ($this->compress == false) {
$this->instance->setOption(\Memcached::OPT_COMPRESSION, false);
}

$this->instance->addServer($host, $port, $weight);

$this->alive = $this->instance->set(self::class, time());
Expand Down Expand Up @@ -117,9 +117,9 @@ public function clean($delay = 0)
* {@inheritDoc}
* @see \OnPHP\Core\Cache\CachePeer::increment()
*/
public function increment($key, $value)
public function increment($key, int $value = 1)
{
$result = $this->instance->increment($key, $value = 1);
$result = $this->instance->increment($key, $value);

$this->processResultCode();

Expand All @@ -130,7 +130,7 @@ public function increment($key, $value)
* {@inheritDoc}
* @see \OnPHP\Core\Cache\CachePeer::decrement()
*/
public function decrement($key, $value = 1)
public function decrement($key, int $value = 1)
{
$result = $this->instance->decrement($key, $value);

Expand All @@ -149,7 +149,7 @@ public function getList($indexes)

$this->processResultCode();

return ($list !== false) ? $list : array();
return ($list !== false && count($list) > 0) ? $list : null;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/ReadOnlyPeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public function clean()
throw new UnsupportedMethodException();
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
throw new UnsupportedMethodException();
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
throw new UnsupportedMethodException();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/RubberFileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function clean()
return parent::clean();
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
$path = $this->makePath($key);

Expand All @@ -83,7 +83,7 @@ public function increment($key, $value)
return null;
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
$path = $this->makePath($key);

Expand Down
6 changes: 3 additions & 3 deletions src/Core/Cache/RuntimeMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ public function isAlive()
return true;
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
if (isset($this->cache[$key]))
return $this->cache[$key] += $value;

return null;
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
if (isset($this->cache[$key]))
return $this->cache[$key] -= $value;
Expand Down Expand Up @@ -90,7 +90,7 @@ public function append($key, $data)
protected function store($action, $key, $value, $expires = 0)
{
if ($action == 'add' && isset($this->cache[$key]))
return true;
return false;
elseif ($action == 'replace' && !isset($this->cache[$key]))
return false;

Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/SequentialCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function append($key, $data)
return $this->foreachItem(__METHOD__, func_get_args());
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
throw new UnsupportedMethodException('decrement is not supported');
}
Expand All @@ -112,7 +112,7 @@ public function delete($key)
return $this->foreachItem(__METHOD__, func_get_args());
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
throw new UnsupportedMethodException('increment is not supported');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/SharedMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function __destruct()
} catch (BaseException $e) {/*_*/}
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
if (null !== ($current = $this->get($key))) {
$this->set($key, $current += $value);
Expand All @@ -96,7 +96,7 @@ public function increment($key, $value)
return null;
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
if (null !== ($current = $this->get($key))) {
$this->set($key, $current -= $value);
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/SocketMemcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ public function getList($indexes)
return unserialize($this->parseGetRequest(false));
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
return $this->changeInteger('incr', $key, $value);
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
return $this->changeInteger('decr', $key, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Core/Cache/WatermarkedPeer.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public function mark($className)
return $this;
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
return $this->peer->increment(
$this->getActualWatermark().$key,
$value
);
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
return $this->peer->decrement(
$this->getActualWatermark().$key,
Expand Down
6 changes: 3 additions & 3 deletions src/Core/DB/NoSQL/RedisNoSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function append($key, $data)
}
}

public function decrement($key, $value)
public function decrement($key, int $value = 1)
{
$this->ensureTriedToConnect();

Expand All @@ -118,7 +118,7 @@ public function delete($key)
$this->ensureTriedToConnect();

try {
return $this->redis->delete($key);
return $this->redis->del($key);
} catch (\RedisException $e) {
return $this->alive = false;
}
Expand All @@ -137,7 +137,7 @@ public function get($key)
}
}

public function increment($key, $value)
public function increment($key, int $value = 1)
{
$this->ensureTriedToConnect();

Expand Down
4 changes: 2 additions & 2 deletions src/Core/DB/NoSQL/RedisNoSQLList.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function clear()

public function count()
{
return $this->redis->lsize($this->key);
return $this->redis->lLen($this->key);
}

public function pop()
Expand All @@ -88,7 +88,7 @@ public function range($start, $length = null)

public function get($index)
{
return $this->redis->lget($this->key, $index);
return $this->redis->lIndex($this->key, $index);
}

public function set($index, $value)
Expand Down
Loading

0 comments on commit e82cc8c

Please sign in to comment.