client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VERSION = "v1.0.0" //版本号

)

Variables

This section is empty.

Functions

func Delete

func Delete(tags ...string) (bool, float64, error)

删除标签

请求参数:
 tags ...string : 标签名

反回参数:

bool : 删除的结果
float64 : 执行耗时,单位秒
error : 错误信息

func GetKeys

func GetKeys() ([]interface{}, float64, error)

获取所有的非系统KEYS

请求参数:
 无

反回参数:

interface{} : 标签所对应的数据,单个标签时为data,多个标签时为[]{Ok:bool,Msg:string,Data:interface{}}
float64 : 执行耗时,单位秒
error : 错误信息

func GetUsers

func GetUsers() ([]string, float64, error)

获取所有的用户名列表

请求参数:
  无

反回参数:

interface{} : 标签所对应的数据,单个标签时为data,多个标签时为[]{Ok:bool,Msg:string,Data:interface{}}
float64 : 执行耗时,单位秒
error : 错误信息

func NewClient

func NewClient(params map[string]interface{})

新建内存数据库的连接池:

{
	"hostname":"字符串,输入,服务器的网络地址或机器名,默认值 127.0.0.1"
	"username":"用户名,字符串,缺省值 admin"
	"password":"密码,字符串,缺省值 admin123"
	"langtype":"语言类型,字符串,缺省值 zh-CN"
	"port"    :"端口号,整型,缺省值 9646"
	"size"    :"连接池大小,最小1,最大50"
	"timeout" :"超时时间(毫秒),默认值 3000"
	"max_sec" :"最大租借时间(秒),默认值 3600"
}

func PipeAll

func PipeAll(tag string) (interface{}, float64, error)

从管道中拉取所有数据

请求参数:
 tag string : 标签名

反回参数:

interface{} : 获取到的数据
float64 : 执行耗时,单位秒
error : 错误信息

func PipeLength

func PipeLength(tag string) (int64, float64, error)

获取管道当前的长度

请求参数:
 tag string : 标签名

反回参数:

int64 : 当前管道长度
float64 : 执行耗时,单位秒
error : 错误信息

func PipePull

func PipePull(tag, ptype string) (int64, interface{}, float64, error)

从管道中拉取数据

请求参数:
 tag string : 标签名
 ptype string : 拉取方式, "FIFO"、"LILO"或"FILO"、"LIFO"(不区分大小写)

反回参数:

int64 : 剩余长度
interface{} : 获取到的数据
float64 : 执行耗时,单位秒

error : 错误信息

func PipePush

func PipePush(key string, value interface{}) (int64, float64, error)

压入管道

请求参数:
 key string 标签名
 value interface{} 数值

反回参数:

int64: 当前管道长度
float64 : 执行耗时,单位秒
error : 错误信息

func Read

func Read(tags ...string) (interface{}, float64, error)

读取标签

请求参数:
 tags ...string : 标签名

反回参数:

interface{} : 标签所对应的数据,单个标签时为data,多个标签时为[]{Ok:bool,Msg:string,Data:interface{}}
float64 : 执行耗时,单位秒
error : 错误信息

func SelfDecrease

func SelfDecrease(tag string) (int64, float64, error)

标签自减

请求参数:
 tag string : 标签名

反回参数:

int64 : 当前值
float64 : 执行耗时,单位秒
error : 错误信息

func SelfIncrease

func SelfIncrease(tag string) (int64, float64, error)

标签自增

请求参数:
 tag string : 标签名

反回参数:

int64 : 当前值
float64 : 执行耗时,单位秒
error : 错误信息

func ServerTime

func ServerTime() (time.Time, float64, error)

服务器时间

请求参数:无

反回参数:

time.Time : 时间
float64 : 执行耗时,单位秒
error : 错误信息

func Write

func Write(key string, value interface{}) (interface{}, float64, error)

写单个标签

请求参数:
 kvs map[string]interface{} : 需要写入的数据

反回参数:

interface{}: 返回的数据
float64 : 执行耗时,单位秒
error : 错误信息

func Writes

func Writes(kvs map[string]interface{}) (interface{}, float64, error)

写多个标签

请求参数:
 kvs map[string]interface{} : 需要写入的数据

反回参数:

interface{}: 返回的数据
float64 : 执行耗时,单位秒
error : 错误信息

Types

type ConnHandel

type ConnHandel struct {
	Id   int64    //序号
	Conn net.Conn //通讯连接

	ConnServer bool //与服务器已建立连接
	Logged     bool //是否已登录标志
	Working    bool //工作中

	TxBytes int64 //发送字节数
	RxBytes int64 //接收字节数
	TxTimes int64 //发送次数
	RxTimes int64 //接收次数

	WorkeAt      time.Time //本次开始工作的时间
	LoginAt      time.Time //登录时间
	CreatedAt    time.Time //创建时间
	LoseServerAt time.Time //最近一次连接不上服务器的时间
	// contains filtered or unexported fields
}

一个通讯连接

type ConnPool

type ConnPool struct {
	WorkerChan chan int         //工作通道
	ReqChan    chan int         //请求队列
	ConnChan   chan *ConnHandel //连接句柄队列
	Conns      []*ConnHandel    //连接池

	Version string //版本号
	// contains filtered or unexported fields
}

连接工作池结构

func NewConnPool

func NewConnPool(params map[string]interface{}) *ConnPool

******************************************************************************

  -功能:实例化工作池
  -参数:
	[hostname]  字符串,输入,服务器的网络地址或机器名,默认值 127.0.0.1
	[username]	用户名,字符串,缺省值 admin
	[password]	密码,字符串,缺省值 admin123
	[langtype]	语言类型,字符串,缺省值 zh-CN
	[port]      端口号,整型,缺省值 9646
	[size]      连接池大小,最小1,最大50
	[timeout]   超时时间(毫秒),默认值 3000
	[max_sec]   最大租借时间(秒),默认值 3600
  • 输出:*ConnPool 连接池指针 [error] 创建句柄连接池时候的错误信息
  • 备注:
  • 时间: 2020年6月27日

******************************************************************************

func (*ConnPool) Delete

func (p *ConnPool) Delete(tags ...string) (bool, float64, error)

删除标签

请求参数:
 tags ...string : 标签名

反回参数:

bool : 删除的结果
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) GetKeys

func (p *ConnPool) GetKeys() ([]interface{}, float64, error)

获取所有的非系统KEYS

请求参数:
 无

反回参数:

interface{} : 标签所对应的数据,单个标签时为data,多个标签时为[]{Ok:bool,Msg:string,Data:interface{}}
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) GetUsers

func (p *ConnPool) GetUsers() ([]string, float64, error)

获取所有的用户名列表

请求参数:
 无

反回参数:

interface{} : 标签所对应的数据,单个标签时为data,多个标签时为[]{Ok:bool,Msg:string,Data:interface{}}
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) PipeAll

func (p *ConnPool) PipeAll(tag string) (interface{}, float64, error)

从管道中拉取所有数据 请求参数:

tag string : 标签名

反回参数:

interface{} : 获取到的数据
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) PipeLength

func (p *ConnPool) PipeLength(tag string) (int64, float64, error)

获取管道当前的长度

请求参数:
 tag string : 标签名

反回参数:

int64 : 当前管道长度
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) PipePull

func (p *ConnPool) PipePull(tag, ptype string) (int64, interface{}, float64, error)

从管道中拉取数据

请求参数:
 tag string : 标签名
 ptype string : 拉取方式, "FIFO"、"LILO"或"FILO"、"LIFO"(不区分大小写)

反回参数:

int64 : 剩余长度
interface{} : 获取到的数据
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) PipePush

func (p *ConnPool) PipePush(key string, value interface{}) (int64, float64, error)

压入管道

请求参数:
 key string 标签名
 value interface{} 数值

反回参数:

int64: 当前管道长度
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) Read

func (p *ConnPool) Read(tags ...string) (interface{}, float64, error)

读取标签

请求参数:
 tags ...string : 标签名

反回参数:

interface{} : 标签所对应的数据,单个标签时为data,多个标签时为[]{Ok:bool,Msg:string,Data:interface{}}
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) Request

func (p *ConnPool) Request(funcCode byte, msg interface{}) (*RespMsg, float64, error)

自由请求接口

请求参数:
 funcCode byte : 功能码
 msg interface{} : 符合json结构和功能码要求的信息

反回参数:

interface{} : 服务器返回的数据
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) SelfDecrease

func (p *ConnPool) SelfDecrease(tag string) (int64, float64, error)

标签自减

请求参数:
 tag string : 标签名

反回参数:

int64 : 当前值
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) SelfIncrease

func (p *ConnPool) SelfIncrease(tag string) (int64, float64, error)

标签自增

请求参数:
 tag string : 标签名

反回参数:

int64 : 当前值
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) ServerTime

func (p *ConnPool) ServerTime() (time.Time, float64, error)

服务器时间

请求参数:无

反回参数:

time.Time : 时间
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) Write

func (p *ConnPool) Write(key string, val interface{}) (interface{}, float64, error)

写标签

请求参数:
 kvs map[string]interface{} : 需要写入的数据

反回参数:

interface{}: 返回的数据
float64 : 执行耗时,单位秒
error : 错误信息

func (*ConnPool) Writes

func (p *ConnPool) Writes(kvs map[string]interface{}) (interface{}, float64, error)

写多个标签

请求参数:
 kvs map[string]interface{} : 需要写入的数据

反回参数:

interface{}: 返回的数据
float64 : 执行耗时,单位秒
error : 错误信息

type RespMsg

type RespMsg struct {
	Ok   bool        `json:"ok"`
	Msg  string      `json:"msg"`
	Data interface{} `json:"data"`
}

响应数据的结构

func Request

func Request(funcCode byte, msg interface{}) (*RespMsg, float64, error)

自由请求接口

请求参数:
  funcCode byte : 功能码
  msg interface{} : 符合json结构和功能码要求的信息

反回参数:

interface{} : 服务器返回的数据
float64 : 执行耗时,单位秒
error : 错误信息

type UserMsg

type UserMsg struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

用户数据的结构

Jump to

Keyboard shortcuts

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