11
11
12
12
namespace Symfony \Component \Lock \Store ;
13
13
14
- use Predis \Response \ServerException ;
14
+ use Predis \Response \Error ;
15
15
use Relay \Relay ;
16
16
use Symfony \Component \Lock \Exception \InvalidTtlException ;
17
17
use Symfony \Component \Lock \Exception \LockConflictedException ;
@@ -250,10 +250,10 @@ private function evaluate(string $script, string $resource, array $args): mixed
250
250
}
251
251
252
252
$ result = $ this ->redis ->evalSha ($ scriptSha , array_merge ([$ resource ], $ args ), 1 );
253
+ }
253
254
254
- if (null !== $ err = $ this ->redis ->getLastError ()) {
255
- throw new LockStorageException ($ err );
256
- }
255
+ if (null !== $ err = $ this ->redis ->getLastError ()) {
256
+ throw new LockStorageException ($ err );
257
257
}
258
258
259
259
return $ result ;
@@ -273,37 +273,32 @@ private function evaluate(string $script, string $resource, array $args): mixed
273
273
}
274
274
275
275
$ result = $ client ->evalSha ($ scriptSha , array_merge ([$ resource ], $ args ), 1 );
276
+ }
276
277
277
- if (null !== $ err = $ client ->getLastError ()) {
278
- throw new LockStorageException ($ err );
279
- }
278
+ if (null !== $ err = $ client ->getLastError ()) {
279
+ throw new LockStorageException ($ err );
280
280
}
281
281
282
282
return $ result ;
283
283
}
284
284
285
285
\assert ($ this ->redis instanceof \Predis \ClientInterface);
286
286
287
- try {
288
- return $ this ->redis ->evalSha ($ scriptSha , 1 , $ resource , ...$ args );
289
- } catch (ServerException $ e ) {
290
- // Fallthrough only if we need to load the script
291
- if (self ::NO_SCRIPT_ERROR_MESSAGE !== $ e ->getMessage ()) {
292
- throw new LockStorageException ($ e ->getMessage (), $ e ->getCode (), $ e );
287
+ $ result = $ this ->redis ->evalSha ($ scriptSha , 1 , $ resource , ...$ args );
288
+ if ($ result instanceof Error && self ::NO_SCRIPT_ERROR_MESSAGE === $ result ->getMessage ()) {
289
+ $ result = $ this ->redis ->script ('LOAD ' , $ script );
290
+ if ($ result instanceof Error) {
291
+ throw new LockStorageException ($ result ->getMessage ());
293
292
}
294
- }
295
293
296
- try {
297
- $ this ->redis ->script ('LOAD ' , $ script );
298
- } catch (ServerException $ e ) {
299
- throw new LockStorageException ($ e ->getMessage (), $ e ->getCode (), $ e );
294
+ $ result = $ this ->redis ->evalSha ($ scriptSha , 1 , $ resource , ...$ args );
300
295
}
301
296
302
- try {
303
- return $ this ->redis ->evalSha ($ scriptSha , 1 , $ resource , ...$ args );
304
- } catch (ServerException $ e ) {
305
- throw new LockStorageException ($ e ->getMessage (), $ e ->getCode (), $ e );
297
+ if ($ result instanceof Error) {
298
+ throw new LockStorageException ($ result ->getMessage ());
306
299
}
300
+
301
+ return $ result ;
307
302
}
308
303
309
304
private function getUniqueToken (Key $ key ): string
0 commit comments