Source File
hotkeys_commands.go
Belonging Package
github.com/redis/go-redis/v9
package redisimport ()// HOTKEYS commands are only available on standalone *Client instances.// They are NOT available on ClusterClient, Ring, or UniversalClient because// HOTKEYS is a stateful command requiring session affinity - all operations// (START, GET, STOP, RESET) must be sent to the same Redis node.//// If you are using UniversalClient and need HOTKEYS functionality, you must// type assert to *Client first://// if client, ok := universalClient.(*redis.Client); ok {// result, err := client.HotKeysStart(ctx, args)// // ...// }// HotKeysMetric represents the metrics that can be tracked by the HOTKEYS command.type HotKeysMetric stringconst (// HotKeysMetricCPU tracks CPU time spent on the key (in microseconds).HotKeysMetricCPU HotKeysMetric = "CPU"// HotKeysMetricNET tracks network bytes used by the key (ingress + egress + replication).HotKeysMetricNET HotKeysMetric = "NET")// HotKeysStartArgs contains the arguments for the HOTKEYS START command.// This command is only available on standalone clients due to its stateful nature// requiring session affinity. It must NOT be used on cluster or pooled clients.type HotKeysStartArgs struct {// Metrics to track. At least one must be specified.Metrics []HotKeysMetric// Count is the number of top keys to report.// Default: 10, Min: 10, Max: 64Count uint8// Duration is the auto-stop tracking after this many seconds.// Default: 0 (no auto-stop)Duration int64// Sample is the sample ratio - track keys with probability 1/sample.// Default: 1 (track every key), Min: 1Sample int64// Slots specifies specific hash slots to track (0-16383).// All specified slots must be hosted by the receiving node.// If not specified, all slots are tracked.Slots []uint16}// ErrHotKeysNoMetrics is returned when HotKeysStart is called without any metrics specified.var ErrHotKeysNoMetrics = errors.New("redis: at least one metric must be specified for HOTKEYS START")// HotKeysStart starts collecting hotkeys data.// At least one metric must be specified in args.Metrics.// This command is only available on standalone clients.func ( *Client) ( context.Context, *HotKeysStartArgs) *StatusCmd {:= make([]interface{}, 0, 16)= append(, "hotkeys", "start")// Validate that at least one metric is specifiedif len(.Metrics) == 0 {:= NewStatusCmd(, ...).SetErr(ErrHotKeysNoMetrics)return}= append(, "metrics", len(.Metrics))for , := range .Metrics {= append(, strings.ToLower(string()))}if .Count > 0 {= append(, "count", .Count)}if .Duration > 0 {= append(, "duration", .Duration)}if .Sample > 0 {= append(, "sample", .Sample)}if len(.Slots) > 0 {= append(, "slots", len(.Slots))for , := range .Slots {= append(, )}}:= NewStatusCmd(, ...)_ = .Process(, )return}// HotKeysStop stops the ongoing hotkeys collection session.// This command is only available on standalone clients.func ( *Client) ( context.Context) *StatusCmd {:= NewStatusCmd(, "hotkeys", "stop")_ = .Process(, )return}// HotKeysReset discards the last hotkeys collection session results.// Returns an error if tracking is currently active.// This command is only available on standalone clients.func ( *Client) ( context.Context) *StatusCmd {:= NewStatusCmd(, "hotkeys", "reset")_ = .Process(, )return}// HotKeysGet retrieves the results of the ongoing or last hotkeys collection session.// This command is only available on standalone clients.func ( *Client) ( context.Context) *HotKeysCmd {:= NewHotKeysCmd(, "hotkeys", "get")_ = .Process(, )return}
![]() |
The pages are generated with Golds v0.8.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |