1: <?php
2: /**
3: * Wei Framework
4: *
5: * @copyright Copyright (c) 2008-2015 Twin Huang
6: * @license http://opensource.org/licenses/mit-license.php MIT License
7: */
8:
9: namespace Wei;
10:
11: /**
12: * A counter service
13: *
14: * @author Twin Huang <twinhuang@qq.com>
15: * @property Cache $cache A cache service
16: */
17: class Counter extends Base
18: {
19: /**
20: * Increment an item
21: *
22: * @param string $key The name of item
23: * @param int $offset The value to increased
24: * @return int|false Returns the new value on success, or false on failure
25: */
26: public function incr($key, $offset = 1)
27: {
28: return $this->cache->incr($key, $offset);
29: }
30:
31: /**
32: * Decrement an item
33: *
34: * @param string $key The name of item
35: * @param int $offset The value to be decreased
36: * @return int|false Returns the new value on success, or false on failure
37: */
38: public function decr($key, $offset = 1)
39: {
40: return $this->cache->decr($key, $offset);
41: }
42:
43: /**
44: * Retrieve an item
45: *
46: * @param string $key The name of item
47: * @return mixed
48: */
49: public function get($key)
50: {
51: return $this->cache->get($key);
52: }
53:
54: /**
55: * Store an item
56: *
57: * @param string $key The name of item
58: * @param mixed $value The value of item
59: * @return bool
60: */
61: public function set($key, $value)
62: {
63: return $this->cache->set($key, $value);
64: }
65:
66: /**
67: * Check if an item is exists
68: *
69: * @param string $key
70: * @return bool
71: */
72: public function exits($key)
73: {
74: return $this->cache->exists($key);
75: }
76:
77: /**
78: * Remove an item
79: *
80: * @param string $key The name of item
81: * @return bool
82: */
83: public function remove($key)
84: {
85: return $this->cache->remove($key);
86: }
87: }