Documentation ¶
Overview ¶
Package keymod provides functions for modifying keys.
This package is particularly useful when working with distributed caching systems like Redis Cluster, where keys containing "{hashTag}" are ensured to exist on the same node. This allows related keys to be stored together, enabling multi-key operations like transactions and Lua scripts.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Modify ¶ added in v0.7.0
Modify applies the given Mod functions to a key.
This can be used to apply multiple modifications to a key, such as adding a prefix and a hash tag.
Example:
key := Modify("profile", PrefixModifier("user123", ":"), HashTagModifier("user123")) // "{user123}user123:profile"
Types ¶
type Mod ¶ added in v0.7.0
Mod is a function that modifies a key.
This can be used to add prefixes, suffixes, or hash tags to keys.
func WithChain ¶ added in v0.7.0
WithChain chains multiple Mod functions together into a single Mod.
This can be used to create complex key modifications in a more readable way.
Example:
modifier := WithChain(PrefixModifier("user123", ":"), HashTagModifier("user123")) key := modifier("profile") // "{user123}user123:profile"
func WithHashTag ¶ added in v0.7.0
WithHashTag wraps the given text in curly braces and prepends it to the key.
This is useful when working with Redis Cluster, as keys with the same hash tag are guaranteed to be on the same node. This allows for multi-key operations to be performed atomically.
Example:
userHashTagModifier := WithHashTag("user123") userKey := userHashTagModifier("profile") // "{user123}profile"
func WithPrefix ¶ added in v0.7.0
WithPrefix prepends the given prefix to the key.
This is useful when working with namespaced keys, where the prefix represents a namespace. The separator is used to separate the prefix from the key.
Example:
userPrefixModifier := WithPrefix("user123", ":") userKey := userPrefixModifier("profile") // "user123:profile"
func WithSuffix ¶ added in v0.7.0
WithSuffix appends the given suffix to the key.
This is useful when working with namespaced keys, where the suffix represents a namespace. The separator is used to separate the key from the suffix.
Example:
userSuffixModifier := WithSuffix("profile", ":") userKey := userSuffixModifier("user123") // "user123:profile"