Skip to content

Commit 4f0cd91

Browse files
committed
perf: faster extract_hash_tag
1 parent d1a78c8 commit 4f0cd91

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/redis_client/cluster/command.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
class RedisClient
88
class Cluster
99
class Command
10-
EMPTY_STRING = ''
10+
EMPTY_STRING = "".freeze
11+
LEFT_BRACKET = "{".freeze
12+
RIGHT_BRACKET = "}".freeze
1113

1214
Detail = Struct.new(
1315
'RedisCommand',
@@ -104,8 +106,8 @@ def determine_optional_key_position(command, option_name) # rubocop:disable Metr
104106
# @see https://redis.io/topics/cluster-spec#keys-hash-tags Keys hash tags
105107
def extract_hash_tag(key)
106108
key = key.to_s
107-
s = key.index('{')
108-
e = key.index('}', s.to_i + 1)
109+
s = key.index(LEFT_BRACKET)
110+
e = key.index(RIGHT_BRACKET, s.to_i + 1)
109111

110112
return EMPTY_STRING if s.nil? || e.nil?
111113

0 commit comments

Comments
 (0)