Skip to content

Commit 981c020

Browse files
authored
fix: make constants private (#372)
1 parent ebf75ac commit 981c020

16 files changed

+54
-13
lines changed

lib/redis_client/cluster.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class RedisClient
1111
class Cluster
1212
ZERO_CURSOR_FOR_SCAN = '0'
1313

14+
private_constant :ZERO_CURSOR_FOR_SCAN
15+
1416
attr_reader :config
1517

1618
def initialize(config, pool: nil, concurrency: nil, **kwargs)

lib/redis_client/cluster/command.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class Command
1212
EMPTY_HASH = {}.freeze
1313
EMPTY_ARRAY = [].freeze
1414

15+
private_constant :EMPTY_STRING, :EMPTY_HASH, :EMPTY_ARRAY
16+
1517
Detail = Struct.new(
1618
'RedisCommand',
1719
:first_key_position,

lib/redis_client/cluster/errors.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ class RedisClient
66
class Cluster
77
ERR_ARG_NORMALIZATION = ->(arg) { Array[arg].flatten.reject { |e| e.nil? || (e.respond_to?(:empty?) && e.empty?) } }
88

9+
private_constant :ERR_ARG_NORMALIZATION
10+
911
class InitialSetupError < ::RedisClient::Error
1012
def initialize(errors)
1113
msg = ERR_ARG_NORMALIZATION.call(errors).map(&:message).uniq.join(',')

lib/redis_client/cluster/key_slot_converter.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class RedisClient
44
class Cluster
55
module KeySlotConverter
6+
HASH_SLOTS = 16_384
67
EMPTY_STRING = ''
78
LEFT_BRACKET = '{'
89
RIGHT_BRACKET = '}'
@@ -41,7 +42,8 @@ module KeySlotConverter
4142
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
4243
].freeze
4344

44-
HASH_SLOTS = 16_384
45+
private_constant :HASH_SLOTS, :EMPTY_STRING,
46+
:LEFT_BRACKET, :RIGHT_BRACKET, :XMODEM_CRC16_LOOKUP
4547

4648
module_function
4749

lib/redis_client/cluster/node.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ class Node
2424
EMPTY_ARRAY = [].freeze
2525
EMPTY_HASH = {}.freeze
2626

27+
private_constant :USE_CHAR_ARRAY_SLOT, :SLOT_SIZE, :MIN_SLOT, :MAX_SLOT,
28+
:DEAD_FLAGS, :ROLE_FLAGS, :EMPTY_ARRAY, :EMPTY_HASH
29+
2730
ReloadNeeded = Class.new(::RedisClient::Error)
2831

2932
Info = Struct.new(
@@ -45,6 +48,8 @@ class CharArray
4548
BASE = ''
4649
PADDING = '0'
4750

51+
private_constant :BASE, :PADDING
52+
4853
def initialize(size, elements)
4954
@elements = elements
5055
@string = String.new(BASE, encoding: Encoding::BINARY, capacity: size)

lib/redis_client/cluster/node/base_topology.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class BaseTopology
88
EMPTY_HASH = {}.freeze
99
EMPTY_ARRAY = [].freeze
1010

11+
private_constant :IGNORE_GENERIC_CONFIG_KEYS, :EMPTY_HASH, :EMPTY_ARRAY
12+
1113
attr_reader :clients, :primary_clients, :replica_clients
1214

1315
def initialize(pool, concurrent_worker, **kwargs)

lib/redis_client/cluster/node/latency_replica.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class LatencyReplica < BaseTopology
99
DUMMY_LATENCY_MSEC = 100 * 1000 * 1000
1010
MEASURE_ATTEMPT_COUNT = 10
1111

12+
private_constant :DUMMY_LATENCY_MSEC, :MEASURE_ATTEMPT_COUNT
13+
1214
def clients_for_scanning(seed: nil) # rubocop:disable Lint/UnusedMethodArgument
1315
@clients_for_scanning
1416
end

lib/redis_client/cluster/node_key.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Cluster
88
module NodeKey
99
DELIMITER = ':'
1010

11+
private_constant :DELIMITER
12+
1113
module_function
1214

1315
def hashify(node_key)

lib/redis_client/cluster/normalized_cmd_name.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ class NormalizedCmdName
99

1010
EMPTY_STRING = ''
1111

12+
private_constant :EMPTY_STRING
13+
1214
def initialize
1315
@cache = {}
1416
@mutex = Mutex.new

lib/redis_client/cluster/pub_sub.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ def spawn_worker(client, queue)
4444

4545
BUF_SIZE = Integer(ENV.fetch('REDIS_CLIENT_PUBSUB_BUF_SIZE', 1024))
4646

47+
private_constant :BUF_SIZE
48+
4749
def initialize(router, command_builder)
4850
@router = router
4951
@command_builder = command_builder

0 commit comments

Comments
 (0)