godis

package module
v0.0.0-...-4feab52 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

README

godis

A Redis client for Go.

Getting started

import (
    "github.com/Haylen-Z/godis"
)

client, err := godis.NewClient(&godis.ClientConfig{Address: "127.0.0.1:6379"})
defer client.Close()
ctx := context.Background()

key := "key1"
val : "hh1"
ok, err := client.Set(ctx, key, val, godis.NXArg)
r, err := client.Get(ctx, key)
Pipeline
    pipe := client.Pipeline()
    pipe.Set(key, []byte(val),  godis.NXArg)
    pipe.Get(key)
    rs, err := pipe.Exec(ct)
    // Set return
    setOk := res[0].(bool)
    // Get return
    val := res[1].(*string)

Documentation

Overview

Package godis is a generated GoMock package.

Package godis is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosedPool = fmt.Errorf("connection pool is closed: %w", ErrGodis)
View Source
var ErrConnectionPoolFull = fmt.Errorf("connection pool is full: %w", ErrGodis)
View Source
var ErrGodis = errors.New("godis error")
View Source
var NXArg arg = func() []string {
	return []string{"NX"}
}
View Source
var PERSISTArg arg = func() []string {
	return []string{"PERSIST"}
}
View Source
var XXArg arg = func() []string {
	return []string{"XX"}
}

Functions

func EXATArg

func EXATArg(unixTimeSeconds uint64) arg

func EXArg

func EXArg(seconds uint64) arg

func MINMATCHLENArg

func MINMATCHLENArg(l uint64) arg

func PXATArg

func PXATArg(unixTimeMiliseconds uint64) arg

func PXArg

func PXArg(miliseconds uint64) arg

Types

type Client

type Client interface {
	Close() error
	Pipeline() *Pipeline

	// String
	Append(ctx context.Context, key string, value string) (int64, error)
	Decr(ctx context.Context, key string) (int64, error)
	DecrBy(ctx context.Context, key string, decrement int64) (int64, error)
	Get(ctx context.Context, key string) (*string, error)
	GetDel(ctx context.Context, key string) (*string, error)
	GetEX(ctx context.Context, key string, args ...arg) (*string, error)
	GetRange(ctx context.Context, key string, start int64, end int64) (string, error)
	GetSet(ctx context.Context, key string, value string) (*string, error)
	Incr(ctx context.Context, key string) (int64, error)
	IncrBy(ctx context.Context, key string, increment int64) (int64, error)
	IncrByFloat(ctx context.Context, key string, increment float64) (float64, error)
	MGet(ctx context.Context, keys ...string) ([]*string, error)
	MSet(ctx context.Context, kvs map[string]string) error
	MSetNX(ctx context.Context, kvs map[string]string) (bool, error)
	PSetEX(ctx context.Context, key, value string, milliseconds uint64) error
	Lcs(ctx context.Context, key1 string, key2 string, args ...arg) (string, error)
	LcsLen(ctx context.Context, key1 string, key2 string) (int64, error)
	LcsIdx(ctx context.Context, key1 string, key2 string, args ...arg) (LcsIdxRes, error)
	LcsIdxWithMatchLen(ctx context.Context, key1 string, key2 string, args ...arg) (LcsIdxRes, error)
	Set(ctx context.Context, key string, value string, args ...arg) (bool, error)
	SetEX(ctx context.Context, key, value string, seconds uint64) error
	SetNX(ctx context.Context, key, value string) (bool, error)
	SetRange(ctx context.Context, key string, offset uint, value string) (uint, error)
	StrLen(ctx context.Context, key string) (uint, error)
	SubStr(ctx context.Context, key string, start, end int) (string, error)
}

func NewClient

func NewClient(config *ClientConfig) (Client, error)

type ClientConfig

type ClientConfig struct {
	Address string
	// The maximum number of connections in the connection pool. Default is math.MaxUint.
	PoolMaxConns uint
	// The time to connect to the redis server. Default is 1 second.
	DailTimeOut time.Duration
	// The maximum amount of time a connection may be idle. Default is 30 minute.
	ConIdleTime time.Duration
	// the maxinum number of idle connections in the connection pool. Default is 0.
	// If the value is 0, the maxinum number of idle connections is the same as the maxinum number of connections.
	MaxIdleConns uint

	// TLS
	Tls           bool
	TlsCertPath   string
	TlsCaCertPath string
	TlsKeyPath    string
}

type Command

type Command interface {
	SendReq(ctx context.Context, protocol Protocol) error
	ReadResp(ctx context.Context, protocol Protocol) (interface{}, error)
}

type Connection

type Connection interface {
	Read(ctx context.Context, p []byte) (n int, err error)
	Write(ctx context.Context, p []byte) (n int, err error)
	GetLastUsedAt() time.Time
	IsBroken() bool
	SetBroken()
	Connect() error
	Close() error
}

func NewConnection

func NewConnection(config *ConnectionConfig) Connection

type ConnectionConfig

type ConnectionConfig struct {
	Address     string
	DialTimeOut time.Duration

	Tls           bool
	TlsCertPath   string
	TlsCaCertPath string
	TlsKeyPath    string
}

type ConnectionPool

type ConnectionPool interface {
	GetConnection() (Connection, error)
	Release(Connection) error
	Close() error
}

func NewConnectionPool

func NewConnectionPool(config *ConnectionPoolConfig) ConnectionPool

type ConnectionPoolConfig

type ConnectionPoolConfig struct {
	ConnectionConfig
	ConIdleTime    time.Duration
	ConDialTimeOut time.Duration
	MaxIdleConNum  uint
	MaxConNum      uint
}

type Error

type Error struct {
	Type string
	Msg  string
}

func (Error) Error

func (e Error) Error() string

type LcsIdxMatch

type LcsIdxMatch struct {
	Pos1 [2]int
	Pos2 [2]int
	Len  int
}

func NewLcsIdxMatch

func NewLcsIdxMatch(raw []interface{}) (LcsIdxMatch, error)

type LcsIdxRes

type LcsIdxRes struct {
	Matches []LcsIdxMatch
	Len     int64
}

func NewLcsIdxRes

func NewLcsIdxRes(raw []interface{}) (LcsIdxRes, error)

type MockConn

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

MockConn is a mock of Conn interface.

func NewMockConn

func NewMockConn(ctrl *gomock.Controller) *MockConn

NewMockConn creates a new mock instance.

func (*MockConn) Close

func (m *MockConn) Close() error

Close mocks base method.

func (*MockConn) EXPECT

func (m *MockConn) EXPECT() *MockConnMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockConn) LocalAddr

func (m *MockConn) LocalAddr() net.Addr

LocalAddr mocks base method.

func (*MockConn) Read

func (m *MockConn) Read(arg0 []byte) (int, error)

Read mocks base method.

func (*MockConn) RemoteAddr

func (m *MockConn) RemoteAddr() net.Addr

RemoteAddr mocks base method.

func (*MockConn) SetDeadline

func (m *MockConn) SetDeadline(arg0 time.Time) error

SetDeadline mocks base method.

func (*MockConn) SetReadDeadline

func (m *MockConn) SetReadDeadline(arg0 time.Time) error

SetReadDeadline mocks base method.

func (*MockConn) SetWriteDeadline

func (m *MockConn) SetWriteDeadline(arg0 time.Time) error

SetWriteDeadline mocks base method.

func (*MockConn) Write

func (m *MockConn) Write(arg0 []byte) (int, error)

Write mocks base method.

type MockConnMockRecorder

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

MockConnMockRecorder is the mock recorder for MockConn.

func (*MockConnMockRecorder) Close

func (mr *MockConnMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockConnMockRecorder) LocalAddr

func (mr *MockConnMockRecorder) LocalAddr() *gomock.Call

LocalAddr indicates an expected call of LocalAddr.

func (*MockConnMockRecorder) Read

func (mr *MockConnMockRecorder) Read(arg0 interface{}) *gomock.Call

Read indicates an expected call of Read.

func (*MockConnMockRecorder) RemoteAddr

func (mr *MockConnMockRecorder) RemoteAddr() *gomock.Call

RemoteAddr indicates an expected call of RemoteAddr.

func (*MockConnMockRecorder) SetDeadline

func (mr *MockConnMockRecorder) SetDeadline(arg0 interface{}) *gomock.Call

SetDeadline indicates an expected call of SetDeadline.

func (*MockConnMockRecorder) SetReadDeadline

func (mr *MockConnMockRecorder) SetReadDeadline(arg0 interface{}) *gomock.Call

SetReadDeadline indicates an expected call of SetReadDeadline.

func (*MockConnMockRecorder) SetWriteDeadline

func (mr *MockConnMockRecorder) SetWriteDeadline(arg0 interface{}) *gomock.Call

SetWriteDeadline indicates an expected call of SetWriteDeadline.

func (*MockConnMockRecorder) Write

func (mr *MockConnMockRecorder) Write(arg0 interface{}) *gomock.Call

Write indicates an expected call of Write.

type MockConnection

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

MockConnection is a mock of Connection interface.

func NewMockConnection

func NewMockConnection(ctrl *gomock.Controller) *MockConnection

NewMockConnection creates a new mock instance.

func (*MockConnection) Close

func (m *MockConnection) Close() error

Close mocks base method.

func (*MockConnection) Connect

func (m *MockConnection) Connect() error

Connect mocks base method.

func (*MockConnection) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockConnection) GetLastUsedAt

func (m *MockConnection) GetLastUsedAt() time.Time

GetLastUsedAt mocks base method.

func (*MockConnection) IsBroken

func (m *MockConnection) IsBroken() bool

IsBroken mocks base method.

func (*MockConnection) Read

func (m *MockConnection) Read(arg0 context.Context, arg1 []byte) (int, error)

Read mocks base method.

func (*MockConnection) SetBroken

func (m *MockConnection) SetBroken()

SetBroken mocks base method.

func (*MockConnection) Write

func (m *MockConnection) Write(arg0 context.Context, arg1 []byte) (int, error)

Write mocks base method.

type MockConnectionMockRecorder

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

MockConnectionMockRecorder is the mock recorder for MockConnection.

func (*MockConnectionMockRecorder) Close

func (mr *MockConnectionMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockConnectionMockRecorder) Connect

func (mr *MockConnectionMockRecorder) Connect() *gomock.Call

Connect indicates an expected call of Connect.

func (*MockConnectionMockRecorder) GetLastUsedAt

func (mr *MockConnectionMockRecorder) GetLastUsedAt() *gomock.Call

GetLastUsedAt indicates an expected call of GetLastUsedAt.

func (*MockConnectionMockRecorder) IsBroken

func (mr *MockConnectionMockRecorder) IsBroken() *gomock.Call

IsBroken indicates an expected call of IsBroken.

func (*MockConnectionMockRecorder) Read

func (mr *MockConnectionMockRecorder) Read(arg0, arg1 interface{}) *gomock.Call

Read indicates an expected call of Read.

func (*MockConnectionMockRecorder) SetBroken

func (mr *MockConnectionMockRecorder) SetBroken() *gomock.Call

SetBroken indicates an expected call of SetBroken.

func (*MockConnectionMockRecorder) Write

func (mr *MockConnectionMockRecorder) Write(arg0, arg1 interface{}) *gomock.Call

Write indicates an expected call of Write.

type MockConnectionPool

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

MockConnectionPool is a mock of ConnectionPool interface.

func NewMockConnectionPool

func NewMockConnectionPool(ctrl *gomock.Controller) *MockConnectionPool

NewMockConnectionPool creates a new mock instance.

func (*MockConnectionPool) Close

func (m *MockConnectionPool) Close() error

Close mocks base method.

func (*MockConnectionPool) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockConnectionPool) GetConnection

func (m *MockConnectionPool) GetConnection() (Connection, error)

GetConnection mocks base method.

func (*MockConnectionPool) Release

func (m *MockConnectionPool) Release(arg0 Connection) error

Release mocks base method.

type MockConnectionPoolMockRecorder

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

MockConnectionPoolMockRecorder is the mock recorder for MockConnectionPool.

func (*MockConnectionPoolMockRecorder) Close

Close indicates an expected call of Close.

func (*MockConnectionPoolMockRecorder) GetConnection

func (mr *MockConnectionPoolMockRecorder) GetConnection() *gomock.Call

GetConnection indicates an expected call of GetConnection.

func (*MockConnectionPoolMockRecorder) Release

func (mr *MockConnectionPoolMockRecorder) Release(arg0 interface{}) *gomock.Call

Release indicates an expected call of Release.

type MockProtocol

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

MockProtocol is a mock of Protocol interface.

func NewMockProtocol

func NewMockProtocol(ctrl *gomock.Controller) *MockProtocol

NewMockProtocol creates a new mock instance.

func (*MockProtocol) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockProtocol) GetNextMsgType

func (m *MockProtocol) GetNextMsgType(arg0 context.Context) (MsgType, error)

GetNextMsgType mocks base method.

func (*MockProtocol) ReadArray

func (m *MockProtocol) ReadArray(arg0 context.Context) ([]interface{}, error)

ReadArray mocks base method.

func (*MockProtocol) ReadBulkString

func (m *MockProtocol) ReadBulkString(arg0 context.Context) (*[]byte, error)

ReadBulkString mocks base method.

func (*MockProtocol) ReadError

func (m *MockProtocol) ReadError(arg0 context.Context) (Error, error)

ReadError mocks base method.

func (*MockProtocol) ReadInteger

func (m *MockProtocol) ReadInteger(arg0 context.Context) (int64, error)

ReadInteger mocks base method.

func (*MockProtocol) ReadMap

func (m *MockProtocol) ReadMap(arg0 context.Context) ([]interface{}, error)

ReadMap mocks base method.

func (*MockProtocol) ReadNull

func (m *MockProtocol) ReadNull(arg0 context.Context) error

ReadNull mocks base method.

func (*MockProtocol) ReadSimpleString

func (m *MockProtocol) ReadSimpleString(arg0 context.Context) ([]byte, error)

ReadSimpleString mocks base method.

func (*MockProtocol) WriteBulkString

func (m *MockProtocol) WriteBulkString(arg0 context.Context, arg1 []byte) error

WriteBulkString mocks base method.

func (*MockProtocol) WriteBulkStringArray

func (m *MockProtocol) WriteBulkStringArray(arg0 context.Context, arg1 [][]byte) error

WriteBulkStringArray mocks base method.

type MockProtocolMockRecorder

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

MockProtocolMockRecorder is the mock recorder for MockProtocol.

func (*MockProtocolMockRecorder) GetNextMsgType

func (mr *MockProtocolMockRecorder) GetNextMsgType(arg0 interface{}) *gomock.Call

GetNextMsgType indicates an expected call of GetNextMsgType.

func (*MockProtocolMockRecorder) ReadArray

func (mr *MockProtocolMockRecorder) ReadArray(arg0 interface{}) *gomock.Call

ReadArray indicates an expected call of ReadArray.

func (*MockProtocolMockRecorder) ReadBulkString

func (mr *MockProtocolMockRecorder) ReadBulkString(arg0 interface{}) *gomock.Call

ReadBulkString indicates an expected call of ReadBulkString.

func (*MockProtocolMockRecorder) ReadError

func (mr *MockProtocolMockRecorder) ReadError(arg0 interface{}) *gomock.Call

ReadError indicates an expected call of ReadError.

func (*MockProtocolMockRecorder) ReadInteger

func (mr *MockProtocolMockRecorder) ReadInteger(arg0 interface{}) *gomock.Call

ReadInteger indicates an expected call of ReadInteger.

func (*MockProtocolMockRecorder) ReadMap

func (mr *MockProtocolMockRecorder) ReadMap(arg0 interface{}) *gomock.Call

ReadMap indicates an expected call of ReadMap.

func (*MockProtocolMockRecorder) ReadNull

func (mr *MockProtocolMockRecorder) ReadNull(arg0 interface{}) *gomock.Call

ReadNull indicates an expected call of ReadNull.

func (*MockProtocolMockRecorder) ReadSimpleString

func (mr *MockProtocolMockRecorder) ReadSimpleString(arg0 interface{}) *gomock.Call

ReadSimpleString indicates an expected call of ReadSimpleString.

func (*MockProtocolMockRecorder) WriteBulkString

func (mr *MockProtocolMockRecorder) WriteBulkString(arg0, arg1 interface{}) *gomock.Call

WriteBulkString indicates an expected call of WriteBulkString.

func (*MockProtocolMockRecorder) WriteBulkStringArray

func (mr *MockProtocolMockRecorder) WriteBulkStringArray(arg0, arg1 interface{}) *gomock.Call

WriteBulkStringArray indicates an expected call of WriteBulkStringArray.

type MsgType

type MsgType int
const (
	SimpleStringType MsgType = iota
	BulkStringType
	ArrayType
	IntegerType
	ErrorType
	NullType
	MapType
)

type Pipeline

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

func (*Pipeline) Append

func (p *Pipeline) Append(key string, value string)

func (*Pipeline) Decr

func (p *Pipeline) Decr(key string)

func (*Pipeline) DecrBy

func (p *Pipeline) DecrBy(key string, decrement int64)

func (*Pipeline) Exec

func (p *Pipeline) Exec(ctx context.Context) ([]interface{}, error)

func (*Pipeline) Get

func (p *Pipeline) Get(key string)

func (*Pipeline) GetDel

func (p *Pipeline) GetDel(key string)

func (*Pipeline) GetEX

func (p *Pipeline) GetEX(key string, optArgs ...arg)

func (*Pipeline) GetRange

func (p *Pipeline) GetRange(key string, start int64, end int64)

func (*Pipeline) GetSet

func (p *Pipeline) GetSet(key string, value string)

func (*Pipeline) Incr

func (p *Pipeline) Incr(key string)

func (*Pipeline) IncrBy

func (p *Pipeline) IncrBy(key string, increment int64)

func (*Pipeline) IncrByFloat

func (p *Pipeline) IncrByFloat(key string, increment float64)

func (*Pipeline) Lcs

func (p *Pipeline) Lcs(key1 string, key2 string, args ...arg)

func (*Pipeline) LcsIdx

func (p *Pipeline) LcsIdx(key1 string, key2 string, args ...arg)

func (*Pipeline) LcsIdxWithMatchLen

func (p *Pipeline) LcsIdxWithMatchLen(key1 string, key2 string, args ...arg)

func (*Pipeline) LcsLen

func (p *Pipeline) LcsLen(key1 string, key2 string)

func (*Pipeline) MGet

func (p *Pipeline) MGet(keys ...string)

func (*Pipeline) MSet

func (p *Pipeline) MSet(kvs map[string]string)

func (*Pipeline) MSetNX

func (p *Pipeline) MSetNX(kvs map[string]string)

func (*Pipeline) PSetEX

func (p *Pipeline) PSetEX(key, value string, milliseconds uint64)

func (*Pipeline) ReadResp

func (p *Pipeline) ReadResp(ctx context.Context, protocol Protocol) (interface{}, error)

func (*Pipeline) SendReq

func (p *Pipeline) SendReq(ctx context.Context, protocol Protocol) error

func (*Pipeline) Set

func (p *Pipeline) Set(key string, value string, args ...arg)

func (*Pipeline) SetEX

func (p *Pipeline) SetEX(key, value string, seconds uint64)

func (*Pipeline) SetNX

func (p *Pipeline) SetNX(key, value string)

func (*Pipeline) SetRange

func (p *Pipeline) SetRange(key string, offset uint, value string)

func (*Pipeline) StrLen

func (p *Pipeline) StrLen(key string)

func (*Pipeline) SubStr

func (p *Pipeline) SubStr(key string, start, end int)

type Protocol

type Protocol interface {
	ReadBulkString(ctx context.Context) (*[]byte, error)
	ReadSimpleString(ctx context.Context) ([]byte, error)
	ReadError(ctx context.Context) (Error, error)
	GetNextMsgType(ctx context.Context) (MsgType, error)
	ReadInteger(ctx context.Context) (int64, error)
	ReadNull(ctx context.Context) error
	ReadArray(ctx context.Context) ([]interface{}, error)
	ReadMap(ctx context.Context) ([]interface{}, error)

	WriteBulkString(ctx context.Context, bs []byte) error
	WriteBulkStringArray(ctx context.Context, bss [][]byte) error
}

func NewProtocol

func NewProtocol(c Connection) Protocol

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳