正在显示
1 个修改的文件
包含
20 行增加
和
2 行删除
| @@ -178,7 +178,16 @@ class RedisPool { | @@ -178,7 +178,16 @@ class RedisPool { | ||
| 178 | public function incr($key, $ttl = null){ | 178 | public function incr($key, $ttl = null){ |
| 179 | if($ttl){ | 179 | if($ttl){ |
| 180 | return $this->getClient()->eval( | 180 | return $this->getClient()->eval( |
| 181 | - "local x = redis.call('incr',KEYS[1]);redis.call('expire',KEYS[1],ARGV[1]);return x", | 181 | + " |
| 182 | +if redis.call('exists',KEYS[1]) == 0 then | ||
| 183 | + local x = redis.call('incr',KEYS[1]) | ||
| 184 | + if x then | ||
| 185 | + redis.call('expire',KEYS[1],ARGV[1]) | ||
| 186 | + end | ||
| 187 | + return x | ||
| 188 | +else | ||
| 189 | + return redis.call('incr',KEYS[1]) | ||
| 190 | +end", | ||
| 182 | [$key, $ttl], | 191 | [$key, $ttl], |
| 183 | 1 | 192 | 1 |
| 184 | ); | 193 | ); |
| @@ -197,7 +206,16 @@ class RedisPool { | @@ -197,7 +206,16 @@ class RedisPool { | ||
| 197 | public function decr($key,$ttl = null){ | 206 | public function decr($key,$ttl = null){ |
| 198 | if($ttl){ | 207 | if($ttl){ |
| 199 | return $this->getClient()->eval( | 208 | return $this->getClient()->eval( |
| 200 | - "local x = redis.call('decr',KEYS[1]);redis.call('expire',KEYS[1],ARGV[1]);return x", | 209 | + " |
| 210 | +if redis.call('exists',KEYS[1]) == 0 then | ||
| 211 | + local x = redis.call('decr',KEYS[1]) | ||
| 212 | + if x then | ||
| 213 | + redis.call('expire',KEYS[1],ARGV[1]) | ||
| 214 | + end | ||
| 215 | + return x | ||
| 216 | +else | ||
| 217 | + return redis.call('decr',KEYS[1]) | ||
| 218 | +end", | ||
| 201 | [$key, $ttl], | 219 | [$key, $ttl], |
| 202 | 1 | 220 | 1 |
| 203 | ); | 221 | ); |
-
请 注册 或 登录 后发表评论