RedisCluster.HashSlots (redis_cluster v0.8.0)
View SourceA module for tracking the hash slots in a Redis cluster with an ETS table.
This is not a module you should be calling directly.
You might use all_slots/1 or all_slots_as_table/1 for debugging purposes.
Summary
Types
The range of hash slot values in a Redis cluster.
A tuple containing the hash slot info to be stored in ETS.
Functions
Adds a list of slot IDs to the ETS table for the given configuration.
Returns all slot IDs from the ETS table for the given configuration.
Formats the results of all_slots/1 into a human-readable table format.
Useful to see the current state of the hash slots at a glance.
This is for debugging purposes only.
Will not include nodes that were offline or otherwise unhealthy when the cluster was last queried.
Creates a named ETS table for tracking hash slots.
Deletes all entries in the ETS table for the given configuration. Doesn't delete the table itself.
Looks up the slot ID for a given hash slot and role in the ETS table.
Similar to lookup/4, but returns a list of tuples with host and port instead of the full slot ID.
Convenience function to create a slot ID tuple ready to insert into the ETS table.
Executes a function with a lock on the ETS table for the given configuration. Used to keep operations atomic when modifying the hash slots.
Types
@type hash_slot() :: 0..16383
The range of hash slot values in a Redis cluster.
@type slot_id() :: {RedisCluster.HashSlots, start :: hash_slot(), stop :: hash_slot(), :master | :replica, host :: String.t(), port :: non_neg_integer()}
A tuple containing the hash slot info to be stored in ETS.
Functions
@spec add_slots(RedisCluster.Configuration.t(), [slot_id()]) :: :ok
Adds a list of slot IDs to the ETS table for the given configuration.
@spec all_slots(RedisCluster.Configuration.t()) :: [slot_id()]
Returns all slot IDs from the ETS table for the given configuration.
@spec all_slots_as_table(RedisCluster.Configuration.t()) :: String.t()
Formats the results of all_slots/1 into a human-readable table format.
Useful to see the current state of the hash slots at a glance.
This is for debugging purposes only.
Will not include nodes that were offline or otherwise unhealthy when the cluster was last queried.
@spec create_table(RedisCluster.Configuration.t()) :: :ets.table()
Creates a named ETS table for tracking hash slots.
@spec delete(RedisCluster.Configuration.t()) :: :ok
Deletes all entries in the ETS table for the given configuration. Doesn't delete the table itself.
@spec lookup( RedisCluster.Configuration.t(), hash_slot(), :master | :replica | :any, Keyword.t() ) :: slot_id()
Looks up the slot ID for a given hash slot and role in the ETS table.
@spec lookup_conn_info( RedisCluster.Configuration.t(), hash_slot(), :master | :replica | :any, Keyword.t() ) :: [{host :: String.t(), port :: non_neg_integer()}]
Similar to lookup/4, but returns a list of tuples with host and port instead of the full slot ID.
@spec slot_id( hash_slot(), hash_slot(), :master | :replica, host :: String.t(), port :: non_neg_integer() ) :: slot_id()
Convenience function to create a slot ID tuple ready to insert into the ETS table.
@spec with_lock(RedisCluster.Configuration.t(), (-> term())) :: term()
Executes a function with a lock on the ETS table for the given configuration. Used to keep operations atomic when modifying the hash slots.