Documentation ¶
Overview ¶
The client package helps developers connect to Gearmand, send jobs and fetch result.
Index ¶
- Constants
- Variables
- func SelectRandom(pool map[string]*PoolClient, last string) (addr string)
- func SelectWithRate(pool map[string]*PoolClient, last string) (addr string)
- type Client
- func (client *Client) Close() (err error)
- func (client *Client) Do(funcname string, data []byte, flag byte, h ResponseHandler) (handle string, err error)
- func (client *Client) DoBg(funcname string, data []byte, flag byte) (handle string, err error)
- func (client *Client) DoBgWithId(funcname string, data []byte, flag byte, id string) (handle string, err error)
- func (client *Client) DoWithId(funcname string, data []byte, flag byte, h ResponseHandler, id string) (handle string, err error)
- func (client *Client) Echo(data []byte) (echo []byte, err error)
- func (client *Client) Status(handle string) (status *Status, err error)
- type ErrorHandler
- type IdGenerator
- type Pool
- func (pool *Pool) Add(net, addr string, rate int) (err error)
- func (pool *Pool) Close() (err map[string]error)
- func (pool *Pool) Do(funcname string, data []byte, flag byte, h ResponseHandler) (addr, handle string, err error)
- func (pool *Pool) DoBg(funcname string, data []byte, flag byte) (addr, handle string, err error)
- func (pool *Pool) Echo(addr string, data []byte) (echo []byte, err error)
- func (pool *Pool) Remove(addr string)
- func (pool *Pool) Status(addr, handle string) (status *Status, err error)
- type PoolClient
- type Response
- type ResponseHandler
- type SelectionHandler
- type Status
- type StatusHandler
Constants ¶
View Source
const ( Network = "tcp" WorkComplate = dtWorkComplete WorkComplete = dtWorkComplete WorkData = dtWorkData WorkStatus = dtWorkStatus WorkWarning = dtWorkWarning WorkFail = dtWorkFail WorkException = dtWorkException )
View Source
const ( // Job type JobNormal = iota // low level JobLow // high level JobHigh )
Variables ¶
View Source
var ( ErrWorkWarning = errors.New("Work warning") ErrInvalidData = errors.New("Invalid data") ErrInvalidId = errors.New("Invalid ID") ErrWorkFail = errors.New("Work fail") ErrWorkException = errors.New("Work exeption") ErrDataType = errors.New("Invalid data type") ErrLostConn = errors.New("Lost connection with Gearmand") )
View Source
var (
DefaultTimeout time.Duration = time.Second
)
View Source
var (
ErrNotFound = errors.New("Server Not Found")
)
Functions ¶
func SelectRandom ¶
func SelectRandom(pool map[string]*PoolClient, last string) (addr string)
func SelectWithRate ¶
func SelectWithRate(pool map[string]*PoolClient, last string) (addr string)
Types ¶
type Client ¶
type Client struct { sync.Mutex ResponseTimeout time.Duration // response timeout for do() ErrorHandler ErrorHandler // contains filtered or unexported fields }
One client connect to one server. Use Pool for multi-connections.
func (*Client) Do ¶
func (client *Client) Do(funcname string, data []byte, flag byte, h ResponseHandler) (handle string, err error)
Call the function and get a response. flag can be set to: JobLow, JobNormal and JobHigh
func (*Client) DoBg ¶
Call the function in background, no response needed. flag can be set to: JobLow, JobNormal and JobHigh
func (*Client) DoBgWithId ¶
func (client *Client) DoBgWithId(funcname string, data []byte, flag byte, id string) (handle string, err error)
Call the function in background, no response needed. flag can be set to: JobLow, JobNormal and JobHigh
type IdGenerator ¶
type IdGenerator interface {
Id() string
}
ID generator interface. Users can implament this for their own generator.
var ( // Global ID generator // Default is an autoincrement ID generator IdGen IdGenerator )
func NewAutoIncId ¶
func NewAutoIncId() IdGenerator
NewAutoIncId returns an autoincrement ID generator
type Pool ¶
type Pool struct { SelectionHandler SelectionHandler ErrorHandler ErrorHandler Clients map[string]*PoolClient // contains filtered or unexported fields }
type PoolClient ¶
type Response ¶
response
type SelectionHandler ¶
type SelectionHandler func(map[string]*PoolClient, string) string
Click to show internal directories.
Click to hide internal directories.