Documentation
¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( DefaultNodesKeySuffix = "NODES" DefaultNodeExpire = time.Hour )
Variables ¶
View Source
var ( EnableLimit = true DefaultKeyQPSSuffix = ":QPS" )
View Source
var (
NodeID string
)
Functions ¶
This section is empty.
Types ¶
type Hitter ¶
type Hitter struct {
*Node
// contains filtered or unexported fields
}
Example ¶
hitter, err := NewHitter(&HitterOption{
NodeOption: &NodeOption{
Redis: redis.NewClient(&redis.Options{Addr: "localhost:6379"}),
KeyPrefix: "ghit:",
},
ExpireSpec: "@midnight",
QPSShakeCoeff: 2,
FollowInterval: time.Hour * 24,
Key: "run",
EnableLimit: true,
Limit: 1,
})
if err != nil {
panic(err)
}
defer hitter.Close()
if ok, err := hitter.Hit(); err != nil {
// handle error
} else if !ok {
return
}
func NewHitter ¶
func NewHitter(opt *HitterOption) (*Hitter, error)
func (*Hitter) Background ¶
func (h *Hitter) Background()
type HitterOption ¶
type HitterOption struct {
*NodeOption
ExpireSpec string
QPSShakeCoeff float64
EnableMaxSync bool
MaxSyncInterval time.Duration
EnableMinSync bool
MinSyncInterval time.Duration
FollowInterval time.Duration
Key string
KeyQPSSuffix string
KeySuffixFormat string
EnableLimit bool
Limit int64
ExpiredHook func(*Hitter)
SyncedHook func(*Hitter)
}
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Example ¶
expireInterval := time.Hour
node, err := NewNode(&NodeOption{
Redis: redis.NewClient(&redis.Options{Addr: "localhost:6379"}),
KeyPrefix: "ghit:",
ExpireInterval: expireInterval,
})
if err != nil {
panic(err)
}
defer node.Close()
node.Heartbeat()
defer node.Dead()
for {
select {
case <-time.After(expireInterval):
node.Heartbeat()
}
}
func NewNode ¶
func NewNode(opt *NodeOption) (*Node, error)
func (*Node) Background ¶
func (n *Node) Background()
type NodeOption ¶
type Pool ¶
type Pool struct {
*Node
// contains filtered or unexported fields
}
func NewPool ¶
func NewPool(opt *PoolOption) (*Pool, error)
func (*Pool) LoadOrStore ¶
func (p *Pool) LoadOrStore(opt *HitterOption) (*Hitter, error)
type PoolOption ¶
type PoolOption struct {
*NodeOption
}
Click to show internal directories.
Click to hide internal directories.