1 | <?php |
||
12 | class IdGenerator |
||
13 | { |
||
14 | |||
15 | const ID_LENGTH = 10; |
||
16 | const KEY = 'idgenerator:%s'; |
||
17 | const DEFAULT_TYPE = 'lastid'; |
||
18 | |||
19 | /** |
||
20 | * @var Predis |
||
21 | */ |
||
22 | private $redis; |
||
23 | |||
24 | /** |
||
25 | * @param Predis $client |
||
26 | */ |
||
27 | 3 | public function __construct(Predis $client) |
|
31 | |||
32 | /** |
||
33 | * @param string $type |
||
34 | * @return int |
||
35 | */ |
||
36 | 1 | public function generateUniqueId(string $type = self::DEFAULT_TYPE) : int |
|
40 | |||
41 | /** |
||
42 | * @param int $length |
||
43 | * @return string |
||
44 | */ |
||
45 | 1 | public function generateRandomId(int$length = self::ID_LENGTH) : string |
|
51 | } |
||
52 |