hotkey

package
v1.0.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Collector

type Collector struct {
	// contains filtered or unexported fields
}

Collector is used to collect hot keys.

func NewCollector

func NewCollector(capacity uint8, options ...collectorOption) *Collector

NewCollector creates a hot keys collector with given parameters.

func (*Collector) AllocCounter

func (c *Collector) AllocCounter(name string) *Counter

AllocCounter allocates a general counter which is used to record the actual visits of keys.

func (*Collector) HotKeys

func (c *Collector) HotKeys() []HotKey

HotKeys returns the collected hot keys which are sorted by logarithmic hit count.

func (*Collector) Run

func (c *Collector) Run(stop <-chan struct{})

Run runs the collector unitl receive the stop signal.

type Counter

type Counter struct {
	// contains filtered or unexported fields
}

Counter is used to record the actual visits number of keys. To minimize the memory footprint, only the keys that are frequently accessed are recorded.

It's not goroutine-safe, every redis client should have its own.

func NewCounter

func NewCounter(capacity uint8, freeCb func()) *Counter

NewCounter creates a counter with given parameters. NOTE: It's only for test, don't rely on it directly.

func (*Counter) Free

func (c *Counter) Free()

Free frees the counter.

func (*Counter) Incr

func (c *Counter) Incr(key string)

Incr increases the specified key visits.

func (*Counter) Latch

func (c *Counter) Latch() map[string]uint64

Latch returns the cached key visits and reset it.

type HotKey

type HotKey struct {
	Name    string
	Counter *logrithmCounter
}

HotKey represents a hot key.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL