Skip to content

Commit 8d01b6f

Browse files
committed
[#V1] Update docs for exists? and realttl
Enhances Redis key existence and TTL retrieval methods with: - More explicit existence checking logic - Added detailed debug tracing - Improved method documentation Provides clearer insights into key state and operations
1 parent 28b53c5 commit 8d01b6f

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

lib/familia/horreum/commands.rb

+22-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,22 @@ class Horreum
1818
#
1919
module Commands
2020

21+
# Checks if the calling object's key exists in Redis and has a non-zero size.
22+
#
23+
# This method retrieves the Redis URI associated with the calling object's class
24+
# using `Familia.redis_uri_by_class`. It then checks if the specified key exists
25+
# in Redis and that its size is not zero. If debugging is enabled, it logs the
26+
# existence check using `Familia.trace`.
27+
#
28+
# @return [Boolean] Returns `true` if the key exists in Redis and its size is not zero, otherwise `false`.
29+
# @example
30+
# if some_object.exists?
31+
# # perform action
32+
# end
2133
def exists?
22-
# Trace output comes from the class method
23-
self.class.exists? identifier, suffix
34+
true_or_false = self.class.redis.exists?(rediskey) && !size.zero?
35+
Familia.trace :EXISTS, redis, "#{key} #{true_or_false.inspect}", caller(1..1) if Familia.debug?
36+
true_or_false
2437
end
2538

2639
# Sets a timeout on key. After the timeout has expired, the key will
@@ -33,6 +46,13 @@ def expire(ttl = nil)
3346
redis.expire rediskey, ttl.to_i
3447
end
3548

49+
# Retrieves the remaining time to live (TTL) for the object's Redis key.
50+
#
51+
# This method accesses the ovjects Redis client to obtain the TTL of `rediskey`.
52+
# If debugging is enabled, it logs the TTL retrieval operation using `Familia.trace`.
53+
#
54+
# @return [Integer] The TTL of the key in seconds. Returns -1 if the key does not exist
55+
# or has no associated expire time.
3656
def realttl
3757
Familia.trace :REALTTL, redis, redisuri, caller(1..1) if Familia.debug?
3858
redis.ttl rediskey

0 commit comments

Comments
 (0)