lib/picky/backends/redis.rb in picky-4.12.11 vs lib/picky/backends/redis.rb in picky-4.12.12
- old
+ new
@@ -231,38 +231,41 @@
# Assume it's using EVALSHA.
#
begin
if identifiers.size > 1
- if @ids_script_hash
- # Reuse script already installed in Redis.
- #
- client.evalsha @ids_script_hash,
- identifiers,
- [
- generate_intermediate_result_id,
- offset,
- (offset + amount)
- ]
- else
- # Install script in Redis.
- #
- @ids_script_hash = Digest::SHA1.hexdigest @ids_script
- client.eval @ids_script,
- identifiers,
- [
- generate_intermediate_result_id,
- offset,
- (offset + amount)
- ]
- end
+ # Reuse script already installed in Redis.
+ #
+ # Note: This may raise an error in Redis,
+ # when the script is not installed.
+ #
+ client.evalsha @ids_script_hash,
+ identifiers,
+ [
+ generate_intermediate_result_id,
+ offset,
+ (offset + amount)
+ ]
else
# No complex calculation necessary.
#
client.zrange identifiers.first,
offset,
(offset + amount)
end
+ rescue RuntimeError => e # Redis::CommandError
+ # Install script in Redis.
+ #
+ # TODO Use SCRIPT LOAD, then retry?
+ #
+ @ids_script_hash = Digest::SHA1.hexdigest @ids_script
+ client.eval @ids_script,
+ identifiers,
+ [
+ generate_intermediate_result_id,
+ offset,
+ (offset + amount)
+ ]
end
end
end
# Does not use Lua scripting, < Redis 2.6.
\ No newline at end of file