1111
1212namespace Symfony \Component \Lock \Store ;
1313
14- use Predis \Response \ServerException ;
14+ use Predis \Response \Error ;
1515use Relay \Relay ;
1616use Symfony \Component \Lock \Exception \InvalidTtlException ;
1717use Symfony \Component \Lock \Exception \LockConflictedException ;
@@ -250,10 +250,10 @@ private function evaluate(string $script, string $resource, array $args): mixed
250250 }
251251
252252 $ result = $ this ->redis ->evalSha ($ scriptSha , array_merge ([$ resource ], $ args ), 1 );
253+ }
253254
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 );
257257 }
258258
259259 return $ result ;
@@ -273,37 +273,32 @@ private function evaluate(string $script, string $resource, array $args): mixed
273273 }
274274
275275 $ result = $ client ->evalSha ($ scriptSha , array_merge ([$ resource ], $ args ), 1 );
276+ }
276277
277- if (null !== $ err = $ client ->getLastError ()) {
278- throw new LockStorageException ($ err );
279- }
278+ if (null !== $ err = $ client ->getLastError ()) {
279+ throw new LockStorageException ($ err );
280280 }
281281
282282 return $ result ;
283283 }
284284
285285 \assert ($ this ->redis instanceof \Predis \ClientInterface);
286286
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 ());
293292 }
294- }
295293
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 );
300295 }
301296
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 ());
306299 }
300+
301+ return $ result ;
307302 }
308303
309304 private function getUniqueToken (Key $ key ): string
0 commit comments