RedisCluster.HashSlots (redis_cluster v0.8.0)

View Source

A 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

hash_slot()

@type hash_slot() :: 0..16383

The range of hash slot values in a Redis cluster.

slot_id()

@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

add_slots(configuration, slots)

@spec add_slots(RedisCluster.Configuration.t(), [slot_id()]) :: :ok

Adds a list of slot IDs to the ETS table for the given configuration.

all_slots(configuration)

@spec all_slots(RedisCluster.Configuration.t()) :: [slot_id()]

Returns all slot IDs from the ETS table for the given configuration.

all_slots_as_table(config)

@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.

create_table(configuration)

@spec create_table(RedisCluster.Configuration.t()) :: :ets.table()

Creates a named ETS table for tracking hash slots.

delete(configuration)

@spec delete(RedisCluster.Configuration.t()) :: :ok

Deletes all entries in the ETS table for the given configuration. Doesn't delete the table itself.

lookup(configuration, hash_slot, role, opts \\ [])

@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.

lookup_conn_info(config, hash_slot, role, opts \\ [])

@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.

slot_id(start, stop, role, host, port)

@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.

with_lock(configuration, fun)

@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.