Documentation ¶
Overview ¶
Package gossdb the client, derived from the official client, supports connection pooling and USES the same conventions as most clients.
refer to official driver development, add connection pool support, improve protocol implementation, and improve data throughput support for set dependent functions supports zset correlation functions supports hset correlation functions supports queue related functions supports multi correlation functions supports return value type conversion, which makes it easy to convert content from SSDB to the specified type supports serialization of json objects, just open the gossdb.encoding option support automatic connection recovery, support error free connection acquisition, code call is easier Major improvements in 2.0 modify the names of all functions to make them conform to the golang coding program and pass the golint verification improve protocol implementation to improve parsing efficiency improve connection pool mode to improve access efficiency of connection pool. Instead of a single connection pool, the connection pool is a block pool, each block is a separate connection pool, and multiple connection pools collaborate to reduce lock contention time support automatic connection recovery, support error free connection acquisition, code call is easier. Instead of having to determine if the connection was successful and close it manually, you can omit this duplicated code and focus on the business logic the memory leak problem with high concurrency is solved primarily by recycling timers and reusing connections The main configuration item // SSDB IP or host name the Host string // SSDB port the Port int // gets the connection timeout in seconds. Default: 5 GetClientTimeout int // connection read/write timeout in seconds. Default: 60 ReadWriteTimeout int // the connection write timeout, in seconds, is the same as the ReadWriteTimeout if not set. Default: 0 WriteTimeout int // the connection read timeout, in seconds, is the same as the ReadWriteTimeout if not set. Default: 0 ReadTimeout int // maximum number of connections. Default value: 100, integer multiple of PoolSize, if not enough, it will be filled automatically. MaxPoolSize int // minimum number of connections. Default value: 20, integer multiple of PoolSize. MinPoolSize int // the number of connections to the pool block. Default value: 20, when connection pool is expanded and contracted, step by this value, which can be adjusted according to machine performance. PoolSize int // the maximum number of waits. When the connection pool is full, the new connection will wait for the connection in the pool to be released before // ontinuing. This value limits the maximum number of waits. Default: 1000 MaxWaitSize int // the connection status check interval for the cache in the connection pool is in seconds. Default: 30 HealthSecond int // key for connection the Password string // connection write buffer, default 8k, in KB WriteBufferSize int // connection read buffer, default 8k, in KB ReadBufferSize int // if retry is enabled, set to true and try again if the request fails. Default: false RetryEnabled bool // the timeout for creating a connection in seconds. Default: 5 ConnectTimeout int // auto close AutoClose bool More instructions please see [here] (https://gowalker.org/github.com/seefan/gossdb) All apis are essentially faithful to the original API usage of SSDB, with only a few methods added for go features. So you can also refer to the official // documentation. Example 1: use automatic shutdown //open the connection pool, using the default configuration,Host=127.0.0.1,Port=8888,AutoClose=true if err := gossdb.Start(); err != nil { panic(err) } //don't forget to close the connection pool at the end of the session. Of course, if you don't close the connection, the SSDB will also break the // connection due to an error defer gossdb.Shutdown() //use the connection, since AutoClose is true, we did not close the connection manually //gossdb.client () is error-free connection mode, so it can directly call other operation functions after obtaining the connection. If the connection // is wrong or the calling function is wrong, it will return err if v, err := gossdb.Client().Get("a"); err == nil { println(v.String()) } else { println(err.Error()) } Call up is many simple ^_^ Example 2: does not use automatic shutdown, works for a way to connect multiple requests at once // with the configuration file, AutoClose is not set to true err := gossdb.Start(&conf.Config{ Host: "127.0.0.1", Port: 8888, }) if err != nil { panic(err) } defer gossdb.Shutdown() c, err := gossdb.NewClient() if err != nil { panic(err) } defer c.Close() if v, err := c.Get("a"); err == nil { println(v.String()) } else { println(err.Error()) } if v, err := c.Get("b"); err == nil { println(v.String()) } else { println(err.Error()) }
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Client ¶
Client returns a connection If no connection is available in the connection pool, gossdb creates a temporary connection and returns it, and any action on the connection returns an error. This error is used to indicate that the connection pool cannot provide a new connection.
@return PoolClient
这个函数返回一个连接,并且总是成功返回。如果连接池没有可用的连接时,gossdb会创建一个临时的连接并返回, 这个连接进行任何操作都会返回一个错误。这个错误用来标记连接池无法提供新连接。
Example (AutoClose) ¶
Client 注意默认配置里连接自动关闭为true,所以此处没有手工关闭连接。 本地ssdb连接示例。假设host为127.0.0.1,端口为8888
package main import ( "github.com/seefan/gossdb" ) func main() { if err := gossdb.Start(); err != nil { panic(err) } defer gossdb.Shutdown() if v, err := gossdb.Client().Get("a"); err == nil { println(v.String()) } else { println(err.Error()) } }
Output:
func NewClient ¶
NewClient returns a cached connection and possible errors
@return *PoolClient @return error
这个函数返回一个缓存的连接和一个可能的错误,如果成功返回的错误就为nil。
Example (NotAutoClose) ¶
NewClient 注意默认配置里没有把连接自动关闭为true,所以此处手工关闭连接。 本地ssdb连接示例。假设host为127.0.0.1,端口为8888
package main import ( "github.com/seefan/gossdb" "github.com/seefan/gossdb/conf" ) func main() { err := gossdb.Start(&conf.Config{ Host: "127.0.0.1", Port: 8888, }) if err != nil { panic(err) } defer gossdb.Shutdown() c, err := gossdb.NewClient() if err != nil { panic(err) } defer c.Close() if v, err := c.Get("a"); err == nil { println(v.String()) } else { println(err.Error()) } }
Output:
func NewPool ¶
func NewPool(conf *conf.Config) (*pool.Connectors, error)
NewPool start a gossdb pool with the initial parameters.
@param conf initial parameters @return gossdb pool @return error that may occur on startup. Return nil if successful startup
通常使用NewPool启动连接池,初始化参数由外部传入。如果启动成功返回一个连接池和nil,如果失败返回nil和发生的错误。
func Start ¶
Start start a global connection pool. This function can only be started once in the program's lifetime. The Shutdown() is called to close the connection pool when the program ends.
@param cfg initial parameters,optional. Use with default parameters if not specified @return error that may occur on startup. Return nil if successful startup
启动一个全局的连接池,此函数在程序的生命周期内只能启动一次,程序结束时调用Shutdown函数关闭连接池。 参数cfg是可选的,如果没有指定,会使用默认参数连接ssdb,host为127.0.0.1,port为8888,autoclose为true。一般在学习gossdb时用于本地练习。
Types ¶
This section is empty.
Directories ¶
Path | Synopsis |
---|---|
Package client Encapsulates all functions of SSDB 封装ssdb的所有函数
|
Package client Encapsulates all functions of SSDB 封装ssdb的所有函数 |
Package conf gossdb config
|
Package conf gossdb config |
Package pool available index queue
|
Package pool available index queue |
Package ssdbclient Establish a connection with SSDB, parse the data and convert it into a regular format 与ssdb建立连接,对数据进行解析,转换成常规格式
|
Package ssdbclient Establish a connection with SSDB, parse the data and convert it into a regular format 与ssdb建立连接,对数据进行解析,转换成常规格式 |
@Time : 2019-05-07 16:58 @Author : seefan @File : test @Software: gossdb
|
@Time : 2019-05-07 16:58 @Author : seefan @File : test @Software: gossdb |