Documentation ¶
Index ¶
- Constants
- Variables
- func Accept(lis net.Listener)
- func DBConn(driverName, dataSourceName string) (err error)
- func Disover(address string) (err error)
- func GetOffset(page, pageSize int) int
- func GetZRange(page, pageSize int) (start, end int)
- func HandleHTTP()
- func InitLog()
- func JSONServeConn(conn io.ReadWriteCloser)
- func ListenAndJSONServe(address string, port int) error
- func ListenAndServe(address string, port int) error
- func ParseTimeByUUID(uuid string) (dateTime string, err error)
- func RandomString(length int) string
- func RedisConn(host, port, password string, maxIDle, maxActive int) error
- func Register(rcvr interface{}) error
- func RegisterName(name string, rcvr interface{}) error
- func ServeCodec(codec ServerCodec)
- func ServeConn(conn io.ReadWriteCloser)
- func ServeRequest(codec ServerCodec) error
- func Struct2Map(obj interface{}) map[string]interface{}
- func UUID() (uuid string, err error)
- type Base
- type Call
- type Client
- func Connect(serviceName string, args ...string) (*Client, error)
- func Dial(network, address string) (*Client, error)
- func DialHTTP(network, address string) (*Client, error)
- func DialHTTPPath(network, address, path string) (*Client, error)
- func JSONDial(network, address string) (*Client, error)
- func NewClient(conn io.ReadWriteCloser) *Client
- func NewClientWithCodec(codec ClientCodec) *Client
- func NewJSONClient(conn io.ReadWriteCloser) *Client
- type ClientCodec
- type ContextKey
- type ID
- func ParseBase2(id string) (ID, error)
- func ParseBase32(b []byte) (ID, error)
- func ParseBase36(id string) (ID, error)
- func ParseBase58(b []byte) (ID, error)
- func ParseBase64(id string) (ID, error)
- func ParseBytes(id []byte) (ID, error)
- func ParseInt64(id int64) ID
- func ParseIntBytes(id [8]byte) ID
- func ParseString(id string) (ID, error)
- func (f ID) Base2() string
- func (f ID) Base32() string
- func (f ID) Base36() string
- func (f ID) Base58() string
- func (f ID) Base64() string
- func (f ID) Bytes() []byte
- func (f ID) Int64() int64
- func (f ID) IntBytes() [8]byte
- func (f ID) MarshalJSON() ([]byte, error)
- func (f ID) Node() int64
- func (f ID) Step() int64
- func (f ID) String() string
- func (f ID) Time() int64
- func (f *ID) UnmarshalJSON(b []byte) error
- type JSONSyntaxError
- type LogBase
- type LoggerObj
- type LoggerWithBase
- type Node
- type RedisArgs
- type RedisPool
- func (p *RedisPool) DEL(key string) error
- func (p *RedisPool) EXISTS(key string) (bool, error)
- func (p *RedisPool) EXPIRE(key string, seconds int) error
- func (p *RedisPool) GET(key string) (value string, err error)
- func (p *RedisPool) HDEL(key string, fields ...string) (count int, err error)
- func (p *RedisPool) HGET(key, field string) (value string, err error)
- func (p *RedisPool) HGETALL(key string, out interface{}) (err error)
- func (p *RedisPool) HINCRBY(key, field string, increment int64) (value int64, err error)
- func (p *RedisPool) HINCRBYFLOAT(key, field string, increment float64) (value float64, err error)
- func (p *RedisPool) HMGET(key string, fields ...string) (value map[string]string, err error)
- func (p *RedisPool) HSET(key string, fieldValue interface{}) (err error)
- func (p *RedisPool) INCR(key string) (value int64, err error)
- func (p *RedisPool) INCRBY(key string, increment int64) (value int64, err error)
- func (p *RedisPool) INCRBYFLOAT(key string, increment float64) (value float64, err error)
- func (p *RedisPool) SADD(args ...interface{}) error
- func (p *RedisPool) SCARD(key string) (score int, err error)
- func (p *RedisPool) SET(key, value string) error
- func (p *RedisPool) SISMEMBER(key string, value string) (bool, error)
- func (p *RedisPool) SMEMBERS(key string) ([]string, error)
- func (p *RedisPool) SREM(key string, member ...interface{}) error
- func (p *RedisPool) ZADD(key string, scoreMember interface{}) error
- func (p *RedisPool) ZCARD(key string) (score int, err error)
- func (p *RedisPool) ZCOUNT(key string, min, max float64) (count int64, err error)
- func (p *RedisPool) ZINCRBY(key string, increment, member interface{}) (score string, err error)
- func (p *RedisPool) ZRANGE(key string, start, stop int64) (result []string, err error)
- func (p *RedisPool) ZRANGEWITHSCORES(key string, start, stop int64) (result []map[string]float64, err error)
- func (p *RedisPool) ZRANK(key string, member interface{}) (rank int64, err error)
- func (p *RedisPool) ZREM(key string, member ...interface{}) (count int64, err error)
- func (p *RedisPool) ZREMRANGEBYRANK(key string, start, stop int64) (count int64, err error)
- func (p *RedisPool) ZREVRANGE(key string, start, stop int64) (result []string, err error)
- func (p *RedisPool) ZREVRANGEWITHSCORES(key string, start, stop int64) (result []map[string]float64, err error)
- func (p *RedisPool) ZREVRANK(key string, member interface{}) (rank int64, err error)
- func (p *RedisPool) ZSCORE(key string, member interface{}) (score string, err error)
- type Request
- type Response
- type SQLM
- type Server
- func (server *Server) Accept(lis net.Listener)
- func (server *Server) HandleHTTP(rpcPath, debugPath string)
- func (server *Server) Register(rcvr interface{}) error
- func (server *Server) RegisterName(name string, rcvr interface{}) error
- func (server *Server) ServeCodec(codec ServerCodec)
- func (server *Server) ServeConn(conn io.ReadWriteCloser)
- func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (server *Server) ServeRequest(codec ServerCodec) error
- type ServerCodec
- type ServerError
- type Tx
- func (tx Tx) Commit() (err error)
- func (tx Tx) Exec(pattern string, arg interface{}) (result sql.Result, err error)
- func (tx Tx) Query(pattern string, arg interface{}) (rows *sqlx.Rows, err error)
- func (tx Tx) QueryRow(pattern string, arg interface{}) (row *sqlx.Row, err error)
- func (tx Tx) Rollback() (err error)
Constants ¶
const ( DefaultRPCPath = "/_goRPC_" DefaultDebugPath = "/debug/rpc" )
Defaults used by HandleHTTP
Variables ¶
var ( RegisterAddress = ":8500" // RegisterAddress 注册中心地址 Weight = 1 // 权重 )
Register注册相关配置变量
var ( // Epoch is set to the twitter snowflake epoch of Nov 04 2010 01:42:54 UTC in milliseconds // You may customize this to set a different epoch for your application. Epoch int64 = 1288834974657 // NodeBits holds the number of bits to use for Node // Remember, you have a total 22 bits to share between Node/Step NodeBits uint8 = 10 // StepBits holds the number of bits to use for Step // Remember, you have a total 22 bits to share between Node/Step StepBits uint8 = 12 )
var ( ServiceName = "rpc" // 服务名 LogDir = "." // 日志路径 Debug = false // 调试模式 )
变量
var DefaultServer = NewServer()
DefaultServer is the default instance of *Server.
var ErrInvalidBase32 = errors.New("invalid base32")
ErrInvalidBase32 is returned by ParseBase32 when given an invalid []byte
var ErrInvalidBase58 = errors.New("invalid base58")
ErrInvalidBase58 is returned by ParseBase58 when given an invalid []byte
var ErrNil = redis.ErrNil
ErrNil reids的ErrNil
var ErrNoRows = sql.ErrNoRows
ErrNoRows sql的ErrNoRows
var ErrShutdown = errors.New("connection is shut down")
ErrShutdown 连接已断开错误
Functions ¶
func Accept ¶
Accept accepts connections on the listener and serves requests to DefaultServer for each incoming connection. Accept blocks; the caller typically invokes it in a go statement.
func HandleHTTP ¶
func HandleHTTP()
HandleHTTP registers an HTTP handler for RPC messages to DefaultServer on DefaultRPCPath and a debugging handler on DefaultDebugPath. It is still necessary to invoke http.Serve(), typically in a go statement.
func JSONServeConn ¶
func JSONServeConn(conn io.ReadWriteCloser)
JSONServeConn runs the JSON-RPC server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.
func ListenAndJSONServe ¶
ListenAndJSONServe 启动jsonrpc服务
func ParseTimeByUUID ¶
ParseTimeByUUID 根据uuid, 获取生成该uuid的时间
func Register ¶
func Register(rcvr interface{}) error
Register publishes the receiver's methods in the DefaultServer.
func RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func ServeCodec ¶
func ServeCodec(codec ServerCodec)
ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.
func ServeConn ¶
func ServeConn(conn io.ReadWriteCloser)
ServeConn runs the DefaultServer on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec. See NewClient's comment for information about concurrent access.
func ServeRequest ¶
func ServeRequest(codec ServerCodec) error
ServeRequest is like ServeCodec but synchronously serves a single request. It does not close the codec upon completion.
Types ¶
type Base ¶
type Base struct { ClientURI string `json:"clientURI"` // 客户端请求地址 StartTime int64 `json:"startTime"` // 服务器接收到客户端请求的时间 RequestTime int64 `json:"requestTime"` // 请求当前当前服务的发起时间 Platform string `json:"platform"` // 客户端的平台 IP string `json:"ip"` // 客户端ip TraceID string `json:"traceID"` // traceID AppName string `json:"appName"` // appName AppCode string `json:"appCode"` // appcode AppVersion string `json:"appVersion"` // appversion UUID string `json:"uuid"` // 用户uuid Username string `json:"username"` // 用户名 }
Base 存放一些请求的基本字段
type Call ¶
type Call struct { ServiceMethod string // The name of the service and method to call. Args interface{} // The argument to the function (*struct). Reply interface{} // The reply from the function (*struct). Error error // After completion, the error status. Done chan *Call // Receives *Call when Go is complete. }
Call represents an active RPC.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents an RPC Client. There may be multiple outstanding Calls associated with a single Client, and a Client may be used by multiple goroutines simultaneously.
func DialHTTP ¶
DialHTTP connects to an HTTP RPC server at the specified network address listening on the default HTTP RPC path.
func DialHTTPPath ¶
DialHTTPPath connects to an HTTP RPC server at the specified network address and path.
func NewClient ¶
func NewClient(conn io.ReadWriteCloser) *Client
NewClient returns a new Client to handle requests to the set of services at the other end of the connection. It adds a buffer to the write side of the connection so the header and payload are sent as a unit.
The read and write halves of the connection are serialized independently, so no interlocking is required. However each half may be accessed concurrently so the implementation of conn should protect against concurrent reads or concurrent writes.
func NewClientWithCodec ¶
func NewClientWithCodec(codec ClientCodec) *Client
NewClientWithCodec is like NewClient but uses the specified codec to encode requests and decode responses.
func NewJSONClient ¶
func NewJSONClient(conn io.ReadWriteCloser) *Client
NewJSONClient returns a new Client to handle requests to the set of services at the other end of the connection.
func (*Client) Call ¶
func (client *Client) Call(ctx context.Context, serviceMethod string, args interface{}, reply interface{}) error
Call invokes the named function, waits for it to complete, and returns its error status.
func (*Client) Close ¶
Close calls the underlying codec's Close method. If the connection is already shutting down, ErrShutdown is returned.
func (*Client) Go ¶
func (client *Client) Go(ctx context.Context, serviceMethod string, args interface{}, reply interface{}, done chan *Call) *Call
Go invokes the function asynchronously. It returns the Call structure representing the invocation. The done channel will signal when the call is complete by returning the same Call object. If done is nil, Go will allocate a new channel. If non-nil, done must be buffered or Go will deliberately crash.
type ClientCodec ¶
type ClientCodec interface { WriteRequest(*Request, *Base, interface{}) error ReadResponseHeader(*Response) error ReadResponseBody(interface{}) error Close() error }
A ClientCodec implements writing of RPC requests and reading of RPC responses for the client side of an RPC session. The client calls WriteRequest to write a request to the connection and calls ReadResponseHeader and ReadResponseBody in pairs to read responses. The client calls Close when finished with the connection. ReadResponseBody may be called with a nil argument to force the body of the response to be read and then discarded. See NewClient's comment for information about concurrent access.
func NewClientCodec ¶
func NewClientCodec(conn io.ReadWriteCloser) ClientCodec
NewClientCodec returns a new ClientCodec using JSON-RPC on conn.
type ID ¶
type ID int64
An ID is a custom type used for a snowflake ID. This is used so we can attach methods onto the ID.
func ParseBase2 ¶
ParseBase2 converts a Base2 string into a snowflake ID
func ParseBase32 ¶
ParseBase32 parses a base32 []byte into a snowflake ID NOTE: There are many different base32 implementations so becareful when doing any interoperation.
func ParseBase36 ¶
ParseBase36 converts a Base36 string into a snowflake ID
func ParseBase58 ¶
ParseBase58 parses a base58 []byte into a snowflake ID
func ParseBase64 ¶
ParseBase64 converts a base64 string into a snowflake ID
func ParseBytes ¶
ParseBytes converts a byte slice into a snowflake ID
func ParseIntBytes ¶
ParseIntBytes converts an array of bytes encoded as big endian integer as a snowflake ID
func ParseString ¶
ParseString converts a string into a snowflake ID
func (ID) Base32 ¶
Base32 uses the z-base-32 character set but encodes and decodes similar to base58, allowing it to create an even smaller result string. NOTE: There are many different base32 implementations so becareful when doing any interoperation.
func (ID) IntBytes ¶
IntBytes returns an array of bytes of the snowflake ID, encoded as a big endian integer.
func (ID) MarshalJSON ¶
MarshalJSON returns a json byte array string of the snowflake ID.
func (ID) Node ¶
Node returns an int64 of the snowflake ID node number DEPRECATED: the below function will be removed in a future release.
func (ID) Step ¶
Step returns an int64 of the snowflake step (or sequence) number DEPRECATED: the below function will be removed in a future release.
func (ID) Time ¶
Time returns an int64 unix timestamp in milliseconds of the snowflake ID time DEPRECATED: the below function will be removed in a future release.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON converts a json byte array of a snowflake ID into an ID type.
type JSONSyntaxError ¶
type JSONSyntaxError struct {
// contains filtered or unexported fields
}
A JSONSyntaxError is returned from UnmarshalJSON if an invalid ID is provided.
func (JSONSyntaxError) Error ¶
func (j JSONSyntaxError) Error() string
type LogBase ¶
type LogBase struct { ClientURI string `json:"clientURI"` // 客户端请求地址 URI string `json:"uri"` // 当前服务被请求地址(service/receiver/method) StartTime int64 `json:"startTime"` // 服务器接收到客户端请求的时间 RequestTime int64 `json:"requestTime"` // 请求当前当前服务的发起时间 Platform string `json:"platform"` // 客户端的平台 SpanLog bool `json:"spanLog"` // 是否是span日志 IP string `json:"ip"` // 客户端ip TraceID string `json:"traceID"` // traceID AppName string `json:"appName"` // appName AppCode string `json:"appCode"` // appCode AppVersion string `json:"appVersion"` // appVersion ReceiveTime int64 `json:"receiveTime"` // 当前服务接收到请求的时间 ResponseTime int64 `json:"responseTime"` // 当前服务响应请求的时间 }
LogBase 日志基础信息
type LoggerWithBase ¶
type LoggerWithBase struct {
// contains filtered or unexported fields
}
LoggerWithBase LoggerWithBase
func (*LoggerWithBase) Debug ¶
func (l *LoggerWithBase) Debug(msg string, fields ...interface{})
Debug debug日志实现
func (*LoggerWithBase) Error ¶
func (l *LoggerWithBase) Error(msg string, fields ...interface{})
Error error日志实现
func (*LoggerWithBase) Info ¶
func (l *LoggerWithBase) Info(msg string, fields ...interface{})
Info info日志实现
func (*LoggerWithBase) Warn ¶
func (l *LoggerWithBase) Warn(msg string, fields ...interface{})
Warn warn日志实现
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
A Node struct holds the basic information needed for a snowflake generator node
type RedisPool ¶
RedisPool redis连接池
var Redis *RedisPool
Redis 存放redis连接池的变量
func (*RedisPool) HGETALL ¶
HGETALL 返回哈希表 key 中,所有的域和值,并赋值给out(out是一个结构体的指针) out 字段使用"redis" tag 作匹配
func (*RedisPool) HINCRBY ¶
HINCRBY 为哈希表 key 中的域 field 的值加上增量 increment 。 增量也可以为负数,相当于对给定域进行减法操作。 如果 key 不存在,一个新的哈希表被创建并执行 HINCRBY 命令。 如果域 field 不存在,那么在执行命令前,域的值被初始化为 0 。 对一个储存字符串值的域 field 执行 HINCRBY 命令将造成一个错误。 本操作的值被限制在 64 位(bit)有符号数字表示之内。 返回值: 执行 HINCRBY 命令之后,哈希表 key 中域 field 的值。
func (*RedisPool) HINCRBYFLOAT ¶
HINCRBYFLOAT 为哈希表 key 中的域 field 加上浮点数增量 increment 。 如果哈希表中没有域 field ,那么 HINCRBYFLOAT 会先将域 field 的值设为 0 ,然后再执行加法操作。 如果键 key 不存在,那么 HINCRBYFLOAT 会先创建一个哈希表,再创建域 field ,最后再执行加法操作。 无论加法计算所得的浮点数的实际精度有多长, INCRBYFLOAT 命令的计算结果最多只保留小数点的后十七位。 当以下任意一个条件发生时,返回一个错误:
1.域 field 的值不是字符串类型(因为 redis 中的数字和浮点数都以字符串的形式保存,所以它们都属于字符串类型) 2.域 field 当前的值或给定的增量 increment 不能解释(parse)为双精度浮点数
返回值: 执行加法操作之后 field 域的值。
func (*RedisPool) HMGET ¶
HMGET 返回哈希表 key 中,一个或多个给定域的值。 如果给定的域不存在于哈希表,那么返回一个 nil 值。 因为不存在的 key 被当作一个空哈希表来处理,所以对一个不存在的 key 进行 HMGET 操作将返回一个只带有 nil 值的表。
func (*RedisPool) HSET ¶
-------------------------------------------------------------------------------------------------------------// ---------------------------------------------------- hash ----------------------------------------------------// HSET 作同时将多个 field-value (域-值)对设置到哈希表 key 中 此命令会覆盖哈希表中已存在的域
func (*RedisPool) INCR ¶
INCR 为键 key 储存的数字值加上一。 如果键 key 不存在, 那么它的值会先被初始化为 0 , 然后再执行 INCR 命令。 如果键 key 储存的值不能被解释为数字, 那么 INCR 命令将返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 返回值: INCR 命令会返回键 key 在执行加一操作之后的值。
func (*RedisPool) INCRBY ¶
INCRBY 为键 key 储存的数字值加上增量 increment 。 如果键 key 不存在, 那么键 key 的值会先被初始化为 0 , 然后再执行 INCRBY 命令。 如果键 key 储存的值不能被解释为数字, 那么 INCRBY 命令将返回一个错误。 本操作的值限制在 64 位(bit)有符号数字表示之内。 返回值: 在加上增量 increment 之后, 键 key 的值。
func (*RedisPool) INCRBYFLOAT ¶
INCRBYFLOAT 为键 key 储存的值加上浮点数增量 increment 。 如果键 key 不存在, 那么 INCRBYFLOAT 会先将键 key 的值设为 0 , 然后再执行加法操作。 如果命令执行成功, 那么键 key 的值会被更新为执行加法计算之后的新值, 并且新值会以字符串的形式返回给调用者。 无论加法计算所得的浮点数的实际精度有多长, INCRBYFLOAT 命令的计算结果最多只保留小数点的后十七位。 当以下任意一个条件发生时, 命令返回一个错误:
键 key 的值不是字符串类型(因为 Redis 中的数字和浮点数都以字符串的形式保存,所以它们都属于字符串类型); 1.键 key 当前的值或者给定的增量 increment 不能被解释(parse)为双精度浮点数。
本操作的值限制在 64 位(bit)有符号数字表示之内。 返回值: 在加上增量 increment 之后, 键 key 的值。
func (*RedisPool) SADD ¶
SADD 将一个或多个 member 元素加入到集合 key 当中,已经存在于集合的 member 元素将被忽略。 假如 key 不存在,则创建一个只包含 member 元素作成员的集合。 当 key 不是集合类型时,返回一个错误。
func (*RedisPool) SET ¶
SET 将字符串值 value 关联到 key 。 如果 key 已经持有其他值, SET 就覆写旧值, 无视类型。 特别注意:无视类型覆盖 当 SET 命令对一个带有生存时间(TTL)的键进行设置之后, 该键原有的 TTL 将被清除。
func (*RedisPool) SISMEMBER ¶
SISMEMBER 判断 value 元素是否集合 key 的成员 如果 member 元素是集合的成员,返回 true 。 如果 member 元素不是集合的成员,或 key 不存在,返回 false 。
func (*RedisPool) ZADD ¶
-------------------------------------------------------------------------------------------------------------// ---------------------------------------------------- zset ----------------------------------------------------// ZADD 将一个或多个 member 元素及其 score 值加入到有序集 key 当中。 如果某个 member 已经是有序集的成员,那么更新这个 member 的 score 值,并通过重新插入这个 member 元素,来保证该 member 在正确的位置上。 score 值可以是整数值或双精度浮点数。 如果 key 不存在,则创建一个空的有序集并执行 ZADD 操作。 当 key 存在但不是有序集类型时,返回一个错误。
使用例子:
scoreMember := map[int]string{111: "a", 101: "b"} if err := conn.ZADD("testZSET", scoreMember); err != nil { t.Error(err) }
func (*RedisPool) ZCARD ¶
ZCARD 返回有序集 key 的基数(集合中元素的数量)。 当 key 存在且是有序集类型时,返回有序集的基数。 当 key 不存在时,返回 0 。
func (*RedisPool) ZCOUNT ¶
ZCOUNT 返回有序集 key 中, score 值在 min 和 max 之间(默认包括 score 值等于 min 或 max )的成员的数量。 返回值: score 值在 min 和 max 之间的成员的数量。
func (*RedisPool) ZINCRBY ¶
ZINCRBY 为有序集 key 的成员 member 的 score 值加上增量 increment 。 可以通过传递一个负数值 increment ,让 score 减去相应的值,比如 ZINCRBY key -5 member ,就是让 member 的 score 值减去 5 当 key 不存在,或 member 不是 key 的成员时, ZINCRBY key increment member 等同于 ZADD key increment member 。 当 key 不是有序集类型时,返回一个错误。 score 值可以是整数值或双精度浮点数。
func (*RedisPool) ZRANGE ¶
ZRANGE 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递增(从小到大)来排序。 具有相同 score 值的成员按字典序(lexicographical order )来排列。 下标参数 start 和 stop 都以 0 为底,也就是说,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。 你也可以使用负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。 超出范围的下标并不会引起错误。 比如说,当 start 的值比有序集的最大下标还要大,或是 start > stop 时, ZRANGE 命令只是简单地返回一个空列表。 另一方面,假如 stop 参数的值比有序集的最大下标还要大,那么 Redis 将 stop 当作最大下标来处理。 返回值: 指定区间内的有序集成员的列表。
func (*RedisPool) ZRANGEWITHSCORES ¶
func (p *RedisPool) ZRANGEWITHSCORES(key string, start, stop int64) (result []map[string]float64, err error)
ZRANGEWITHSCORES 使用WITHSCORES选项的ZRANGE
func (*RedisPool) ZRANK ¶
ZRANK 返回有序集 key 中成员 member 的排名。其中有序集成员按 score 值递增(从小到大)顺序排列。 排名以 0 为底,也就是说, score 值最小的成员排名为 0 。 使用 ZREVRANK key member 命令可以获得成员按 score 值递减(从大到小)排列的排名。 返回值:
如果 member 是有序集 key 的成员,返回 member 的排名。 如果 member 不是有序集 key 的成员,返回 -1。
func (*RedisPool) ZREMRANGEBYRANK ¶ added in v0.0.3
ZREMRANGEBYRANK 移除有序集key中,指定排名(rank)区间 start 和 stop 内的所有成员。 下标参数start和stop都是从0开始计数,0是分数最小的那个元素。 索引也可是负数,表示位移从最高分处开始数。 例如,-1是分数最高的元素,-2是分数第二高的,依次类推。
func (*RedisPool) ZREVRANGE ¶
ZREVRANGE 返回有序集 key 中,指定区间内的成员。 其中成员的位置按 score 值递减(从大到小)来排序。 具有相同 score 值的成员按字典序的逆序(reverse lexicographical order)排列。 下标参数 start 和 stop 都以 0 为底,也就是说,以 0 表示有序集第一个成员,以 1 表示有序集第二个成员,以此类推。 你也可以使用负数下标,以 -1 表示最后一个成员, -2 表示倒数第二个成员,以此类推。 超出范围的下标并不会引起错误。 返回值: 指定区间内的有序集成员的列表。
func (*RedisPool) ZREVRANGEWITHSCORES ¶
func (p *RedisPool) ZREVRANGEWITHSCORES(key string, start, stop int64) (result []map[string]float64, err error)
ZREVRANGEWITHSCORES 使用WITHSCORES选项的ZREVRANGE
type Request ¶
type Request struct { ServiceMethod string // format: "Service.Method" Seq uint64 // sequence number chosen by client // contains filtered or unexported fields }
Request is a header written before every RPC call. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.
type Response ¶
type Response struct { ServiceMethod string // echoes that of the Request Seq uint64 // echoes that of the request Error string // error, if any. // contains filtered or unexported fields }
Response is a header written before every RPC return. It is used internally but documented here as an aid to debugging, such as when analyzing network traffic.
type SQLM ¶
SQLM SQLM
var DB SQLM
DB 数据库连接
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an RPC Server.
func (*Server) Accept ¶
Accept accepts connections on the listener and serves requests for each incoming connection. Accept blocks until the listener returns a non-nil error. The caller typically invokes Accept in a go statement.
func (*Server) HandleHTTP ¶
HandleHTTP registers an HTTP handler for RPC messages on rpcPath, and a debugging handler on debugPath. It is still necessary to invoke http.Serve(), typically in a go statement.
func (*Server) Register ¶
Register publishes in the server the set of methods of the receiver value that satisfy the following conditions:
- exported method of exported type
- two arguments, both of exported type
- the second argument is a pointer
- one return value, of type error
It returns an error if the receiver is not an exported type or has no suitable methods. It also logs the error using package log. The client accesses each method using a string of the form "Type.Method", where Type is the receiver's concrete type.
func (*Server) RegisterName ¶
RegisterName is like Register but uses the provided name for the type instead of the receiver's concrete type.
func (*Server) ServeCodec ¶
func (server *Server) ServeCodec(codec ServerCodec)
ServeCodec is like ServeConn but uses the specified codec to decode requests and encode responses.
func (*Server) ServeConn ¶
func (server *Server) ServeConn(conn io.ReadWriteCloser)
ServeConn runs the server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement. ServeConn uses the gob wire format (see package gob) on the connection. To use an alternate codec, use ServeCodec. See NewClient's comment for information about concurrent access.
func (*Server) ServeHTTP ¶
func (server *Server) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP implements an http.Handler that answers RPC requests.
func (*Server) ServeRequest ¶
func (server *Server) ServeRequest(codec ServerCodec) error
ServeRequest 和ServeCodec类似,但是它是同步服务于单个请求. It does not close the codec upon completion.
type ServerCodec ¶
type ServerCodec interface { ReadRequestHeader(*Request) error ReadRequestBase(*Base) error // 读取传递的一些基础参数 ReadRequestBody(interface{}) error WriteResponse(*Response, interface{}) error // Close can be called multiple times and must be idempotent. Close() error }
A ServerCodec implements reading of RPC requests and writing of RPC responses for the server side of an RPC session. The server calls ReadRequestHeader and ReadRequestBody in pairs to read requests from the connection, and it calls WriteResponse to write a response back. The server calls Close when finished with the connection. ReadRequestBody may be called with a nil argument to force the body of the request to be read and discarded. See NewClient's comment for information about concurrent access.
func NewServerCodec ¶
func NewServerCodec(conn io.ReadWriteCloser) ServerCodec
NewServerCodec returns a new ServerCodec using JSON-RPC on conn.
type ServerError ¶
type ServerError string
ServerError represents an error that has been returned from the remote side of the RPC connection.
func (ServerError) Error ¶
func (e ServerError) Error() string