@@ 107-127 (lines=21) @@ | ||
104 | return $result; |
|
105 | } |
|
106 | ||
107 | public function set( $key, $value, $expiry = 0, $flags = 0 ) { |
|
108 | list( $server, $conn ) = $this->getConnection( $key ); |
|
109 | if ( !$conn ) { |
|
110 | return false; |
|
111 | } |
|
112 | $expiry = $this->convertToRelative( $expiry ); |
|
113 | try { |
|
114 | if ( $expiry ) { |
|
115 | $result = $conn->setex( $key, $expiry, $this->serialize( $value ) ); |
|
116 | } else { |
|
117 | // No expiry, that is very different from zero expiry in Redis |
|
118 | $result = $conn->set( $key, $this->serialize( $value ) ); |
|
119 | } |
|
120 | } catch ( RedisException $e ) { |
|
121 | $result = false; |
|
122 | $this->handleException( $conn, $e ); |
|
123 | } |
|
124 | ||
125 | $this->logRequest( 'set', $key, $server, $result ); |
|
126 | return $result; |
|
127 | } |
|
128 | ||
129 | public function delete( $key ) { |
|
130 | list( $server, $conn ) = $this->getConnection( $key ); |
|
@@ 235-258 (lines=24) @@ | ||
232 | return $result; |
|
233 | } |
|
234 | ||
235 | public function add( $key, $value, $expiry = 0 ) { |
|
236 | list( $server, $conn ) = $this->getConnection( $key ); |
|
237 | if ( !$conn ) { |
|
238 | return false; |
|
239 | } |
|
240 | $expiry = $this->convertToRelative( $expiry ); |
|
241 | try { |
|
242 | if ( $expiry ) { |
|
243 | $result = $conn->set( |
|
244 | $key, |
|
245 | $this->serialize( $value ), |
|
246 | [ 'nx', 'ex' => $expiry ] |
|
247 | ); |
|
248 | } else { |
|
249 | $result = $conn->setnx( $key, $this->serialize( $value ) ); |
|
250 | } |
|
251 | } catch ( RedisException $e ) { |
|
252 | $result = false; |
|
253 | $this->handleException( $conn, $e ); |
|
254 | } |
|
255 | ||
256 | $this->logRequest( 'add', $key, $server, $result ); |
|
257 | return $result; |
|
258 | } |
|
259 | ||
260 | /** |
|
261 | * Non-atomic implementation of incr(). |