redrpc

package
v0.0.0-...-77773fb Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultPrefix = "redis_rpc"

	DefaultBLPOPTimeout    = 1 * time.Second
	DefaultResponseTimeout = 1 * time.Second

	DefaultRequestExpire = 120 * time.Second
	DefaultResultExpire  = 120 * time.Second
)

Variables

This section is empty.

Functions

func IsRPCTimeout

func IsRPCTimeout(err error) bool

func IsRemoteException

func IsRemoteException(err error) bool

Types

type Client

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

func NewClient

func NewClient(red *redis.Client, opts *Options) *Client

func NewClientWithAdapter

func NewClientWithAdapter(red DbAdapter, opts *Options) *Client

func (*Client) Call

func (c *Client) Call(funcName string, kwargs map[string]interface{}) (interface{}, error)

func (*Client) CallAsync

func (c *Client) CallAsync(funcName string, kwargs map[string]interface{}) (string, error)

func (*Client) Response

func (c *Client) Response(funcName, reqId string) (interface{}, error)

type DbAdapter

type DbAdapter interface {
	BLPop(timeout time.Duration, keys ...string) ([]string, error)
	RPushEx(key, value string, ttl time.Duration) error
}

type ErrResponse

type ErrResponse struct {
	Ts  string `json:"ts"`
	Err string `json:"err"`
}

type Handler

type Handler interface {
	ServeRPC(Request) (interface{}, error)
}

type HandlerFunc

type HandlerFunc func(Request) (interface{}, error)

func (HandlerFunc) ServeRPC

func (h HandlerFunc) ServeRPC(r Request) (interface{}, error)

type Options

type Options struct {
	Prefix                                                     string
	RequestExpire, ResultExpire, ResponseTimeout, BLPOPTimeout time.Duration
	TimeSource                                                 func() time.Time
}

func OptsWithDefaults

func OptsWithDefaults(o *Options) *Options

type RPCTimeout

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

func (*RPCTimeout) Error

func (e *RPCTimeout) Error() string

type RedisAdapter

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

func (*RedisAdapter) BLPop

func (a *RedisAdapter) BLPop(timeout time.Duration, keys ...string) ([]string, error)

func (*RedisAdapter) RPushEx

func (a *RedisAdapter) RPushEx(key, value string, ttl time.Duration) error

type RemoteException

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

func (*RemoteException) Error

func (e *RemoteException) Error() string

type Request

type Request interface {
	GetValue(name string) interface{}
	GetString(name string) string
}

type RequestImpl

type RequestImpl struct {
	Id string                 `json:"id"`
	Ts string                 `json:"ts"`
	Kw map[string]interface{} `json:"kw"`
}

func (RequestImpl) GetString

func (r RequestImpl) GetString(k string) string

func (RequestImpl) GetValue

func (r RequestImpl) GetValue(k string) interface{}

type ResResponse

type ResResponse struct {
	Ts  string      `json:"ts"`
	Res interface{} `json:"res"`
}

type Server

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

func NewServer

func NewServer(red *redis.Client, opts *Options, handlers map[string]Handler) *Server

func NewServerWithAdapter

func NewServerWithAdapter(red DbAdapter, opts *Options, handlers map[string]Handler) *Server

func (*Server) Close

func (s *Server) Close()

func (*Server) Run

func (s *Server) Run()

func (*Server) RunOnce

func (s *Server) RunOnce() bool

Jump to

Keyboard shortcuts

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