@@ 63-84 (lines=22) @@ | ||
60 | * @param integer $value |
|
61 | * @return integer |
|
62 | */ |
|
63 | public function increment($id, $value = 1) |
|
64 | { |
|
65 | $this->validateIdentifier($id); |
|
66 | ||
67 | $id = $this->getPrefixedIdentifier($id); |
|
68 | $raw = $this->doLoadRaw($id); |
|
69 | ||
70 | if (false !== $raw) { |
|
71 | if ($raw < 0) { |
|
72 | $result = $raw + $value; |
|
73 | $this->doSaveScalar($result, $id); |
|
74 | } else { |
|
75 | $result = $this->getOption('client')->increment($id, $value); |
|
76 | } |
|
77 | } else { |
|
78 | $result = $value; |
|
79 | ||
80 | $this->doSaveScalar($value, $id); |
|
81 | } |
|
82 | ||
83 | return $result; |
|
84 | } |
|
85 | ||
86 | /** |
|
87 | * {@inheritdoc} |
|
@@ 93-115 (lines=23) @@ | ||
90 | * @param integer $value |
|
91 | * @return integer |
|
92 | */ |
|
93 | public function decrement($id, $value = 1) |
|
94 | { |
|
95 | $this->validateIdentifier($id); |
|
96 | ||
97 | $id = $this->getPrefixedIdentifier($id); |
|
98 | $raw = $this->doLoadRaw($id); |
|
99 | ||
100 | if (false !== $raw) { |
|
101 | if ($raw < 0) { |
|
102 | $result = $raw - $value; |
|
103 | ||
104 | $this->doSaveScalar($raw - $value, $id); |
|
105 | } else { |
|
106 | $result = $this->getOption('client')->decrement($id, $value); |
|
107 | } |
|
108 | } else { |
|
109 | $result = -$value; |
|
110 | ||
111 | $this->doSaveScalar($result, $id); |
|
112 | } |
|
113 | ||
114 | return $result; |
|
115 | } |
|
116 | ||
117 | /** |
|
118 | * {@inheritdoc} |