1
|
<?php
|
2
|
|
3
|
/*
|
4
|
* This file is part of the Predis package.
|
5
|
*
|
6
|
* (c) Daniele Alessandri <suppakilla@gmail.com>
|
7
|
*
|
8
|
* For the full copyright and license information, please view the LICENSE
|
9
|
* file that was distributed with this source code.
|
10
|
*/
|
11
|
|
12
|
namespace Predis\Protocol\Text;
|
13
|
|
14
|
use Predis\CommunicationException;
|
15
|
use Predis\Connection\ComposableConnectionInterface;
|
16
|
use Predis\Protocol\ProtocolException;
|
17
|
use Predis\Protocol\ResponseHandlerInterface;
|
18
|
|
19
|
/**
|
20
|
* Implements a response handler for integer replies using the standard wire
|
21
|
* protocol defined by Redis.
|
22
|
*
|
23
|
* @link http://redis.io/topics/protocol
|
24
|
* @author Daniele Alessandri <suppakilla@gmail.com>
|
25
|
*/
|
26
|
class ResponseIntegerHandler implements ResponseHandlerInterface
|
27
|
{
|
28
|
/**
|
29
|
* Handles an integer reply returned by Redis.
|
30
|
*
|
31
|
* @param ComposableConnectionInterface $connection Connection to Redis.
|
32
|
* @param string $number String representation of an integer.
|
33
|
* @return int
|
34
|
*/
|
35
|
public function handle(ComposableConnectionInterface $connection, $number)
|
36
|
{
|
37
|
if (is_numeric($number)) {
|
38
|
return (int) $number;
|
39
|
}
|
40
|
|
41
|
if ($number !== 'nil') {
|
42
|
CommunicationException::handle(new ProtocolException(
|
43
|
$connection, "Cannot parse '$number' as numeric response"
|
44
|
));
|
45
|
}
|
46
|
|
47
|
return null;
|
48
|
}
|
49
|
}
|