rmysql

package module
v0.0.0-...-e4f1ffc Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: MIT Imports: 11 Imported by: 0

README

rmysql

mysql + redis

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Args

func Args(args interface{}) []interface{}

func ArgsString

func ArgsString(fields []string) []interface{}

func ArgsStringAhead

func ArgsStringAhead(key string, fields []string) []interface{}

func CheckError

func CheckError(err error)

func Col

func Col(arr interface{}, result interface{}, field string)

func ColInt

func ColInt(arr interface{}, field string) []int

ColInt 获取结构体数组的整数列。arr:T[]

func ColInt2Str

func ColInt2Str(arr interface{}, field string, fn func(id int) string) []string

func GetField

func GetField(v interface{}, field string) interface{}

func JoinFields

func JoinFields(prefix string, fields ...string) string

func MapIds

func MapIds(ids []int, fn func(id int) string) []string

func Panic

func Panic(msg string, err error)

func PtrValue

func PtrValue(v reflect.Value) reflect.Value

func Unique

func Unique(ids []int) []int

Types

type Dao

type Dao struct {
	Mysql *MysqlService
	Redis *RedisService
	TTL   int64
}

func NewDao

func NewDao(mysql *MysqlService, redis *RedisService, ttl int64) Dao

func (Dao) Close

func (d Dao) Close()

func (Dao) Get

func (d Dao) Get(id int, result interface{}, key string)

func (Dao) List

func (d Dao) List(ids []int, result interface{}, redisKey func(int) string)

func (Dao) ListBySql

func (d Dao) ListBySql(result interface{}, key string, query string, args ...interface{})

List result: eg. &[]table.User

type MysqlConfig

type MysqlConfig struct {
	Url         string
	LogPrefix   string
	Trace       bool
	TraceWriter gorp.GorpLogger
	Engine      string
	Encoding    string
}

type MysqlService

type MysqlService struct {
	*MysqlWrapper
	DbMap           *gorp.DbMap
	Transaction     *gorp.Transaction
	Tx              *MysqlWrapper
	TmpMysqlWrapper *MysqlWrapper
}

func NewMysqlService

func NewMysqlService(url, prefix string, trace bool) *MysqlService

func NewMysqlServiceWithConfig

func NewMysqlServiceWithConfig(config MysqlConfig) *MysqlService

func (*MysqlService) Add

func (s *MysqlService) Add(i interface{})

func (*MysqlService) AddTable

func (s *MysqlService) AddTable(i interface{})

func (*MysqlService) Begin

func (s *MysqlService) Begin()

Begin transaction , in transation we should use `mysql.Tx.Select`

func (*MysqlService) Close

func (s *MysqlService) Close()

func (*MysqlService) Commit

func (s *MysqlService) Commit() error

func (*MysqlService) Rollback

func (s *MysqlService) Rollback() error

func (*MysqlService) WithTransaction

func (s *MysqlService) WithTransaction(fn func())

type MysqlWrapper

type MysqlWrapper struct {
	Executor gorp.SqlExecutor
}

func Wrap

func Wrap(executor gorp.SqlExecutor) *MysqlWrapper

func (*MysqlWrapper) CountByKeys

func (m *MysqlWrapper) CountByKeys(table, appendSql string, kvs ...interface{}) int64

func (*MysqlWrapper) Delete

func (m *MysqlWrapper) Delete(table string, id interface{}) sql.Result

func (*MysqlWrapper) DeleteList

func (m *MysqlWrapper) DeleteList(list ...interface{}) interface{}

func (*MysqlWrapper) Exec

func (m *MysqlWrapper) Exec(query string, args ...interface{}) sql.Result

func (*MysqlWrapper) Get

func (m *MysqlWrapper) Get(i interface{}, id interface{})

func (*MysqlWrapper) GetByKey

func (m *MysqlWrapper) GetByKey(i interface{}, kvs ...interface{})

func (*MysqlWrapper) GetObject

func (m *MysqlWrapper) GetObject(i interface{}, id interface{}, table string, fields []string)

func (*MysqlWrapper) Gets

func (m *MysqlWrapper) Gets(i interface{}, ids ...interface{})

func (*MysqlWrapper) Insert

func (m *MysqlWrapper) Insert(list ...interface{})

func (*MysqlWrapper) List

func (m *MysqlWrapper) List(i interface{}, ids []int)

func (*MysqlWrapper) ListByKeys

func (m *MysqlWrapper) ListByKeys(r interface{}, appendSql string, kvs ...interface{})

GetByKeys eg. var r []UserMajor GetByKeys(&r ,"order by id", "uid",1)

func (*MysqlWrapper) ListObject

func (m *MysqlWrapper) ListObject(r interface{}, ids []int, table string, fields []string)

func (*MysqlWrapper) Select

func (m *MysqlWrapper) Select(i interface{}, query string, args ...interface{})

func (*MysqlWrapper) SelectFloat

func (m *MysqlWrapper) SelectFloat(query string, args ...interface{}) float64

func (*MysqlWrapper) SelectInt

func (m *MysqlWrapper) SelectInt(query string, args ...interface{}) int

func (*MysqlWrapper) SelectInt64

func (m *MysqlWrapper) SelectInt64(query string, args ...interface{}) int64

func (*MysqlWrapper) SelectNullFloat

func (m *MysqlWrapper) SelectNullFloat(query string, args ...interface{}) null.Float

func (*MysqlWrapper) SelectNullInt

func (m *MysqlWrapper) SelectNullInt(query string, args ...interface{}) null.Int

func (*MysqlWrapper) SelectNullStr

func (m *MysqlWrapper) SelectNullStr(query string, args ...interface{}) null.String

func (*MysqlWrapper) SelectOne

func (m *MysqlWrapper) SelectOne(holder interface{}, query string, args ...interface{})

func (*MysqlWrapper) SelectStr

func (m *MysqlWrapper) SelectStr(query string, args ...interface{}) string

func (*MysqlWrapper) Update

func (m *MysqlWrapper) Update(table string, param interface{})

func (*MysqlWrapper) UpdateObjects

func (m *MysqlWrapper) UpdateObjects(list ...interface{}) int64

type RMysqlError

type RMysqlError struct {
	Err error
	Msg string
}

func (RMysqlError) Error

func (r RMysqlError) Error() string

type RedisService

type RedisService struct {
	// // Connected is true when the Service has already connected
	// Connected bool
	// // Config the redis config for this redis
	Redis redis.Conn
}

Service the Redis service, contains the config and the redis Pool

func NewRedisService

func NewRedisService(redisUrl string) *RedisService

NewRedisServices redisUrl like redis://user:secret@localhost:6379/0?foo=bar&qux=baz

func NewService

func NewService(cli redis.Conn) *RedisService

func (*RedisService) AddJsonsId

func (r *RedisService) AddJsonsId(objs interface{}, keyFn func(id int) string, ttl int64)

func (*RedisService) AddJsonsInt

func (r *RedisService) AddJsonsInt(objs interface{}, field string, keyFn func(id int) string, ttl int64)

func (*RedisService) AllExist

func (r *RedisService) AllExist(keys ...string) bool

func (*RedisService) Close

func (r *RedisService) Close()

func (*RedisService) Delete

func (r *RedisService) Delete(key string)

Delete removes redis entry by specific key

func (*RedisService) Discard

func (r *RedisService) Discard()

func (*RedisService) Exec

func (r *RedisService) Exec() (interface{}, error)

func (*RedisService) Exists

func (r *RedisService) Exists(key string) bool

func (*RedisService) Expire

func (r *RedisService) Expire(key string, newSecondsLifeTime int64)

func (*RedisService) Expires

func (r *RedisService) Expires(seconds int64, keys []string)

func (*RedisService) Get

func (r *RedisService) Get(key interface{}) RedisValue

func (*RedisService) GetBytes

func (r *RedisService) GetBytes(key string) []byte

func (*RedisService) GetJson

func (r *RedisService) GetJson(key string, out interface{}) bool

return (exists , error)

func (*RedisService) GetJsonMap

func (r *RedisService) GetJsonMap(keys []string, out interface{}) error

func (*RedisService) GetJsons

func (r *RedisService) GetJsons(keys []string, out interface{}) error

GetJsons eg.GetJsons({"1","2"} , &[]obj)

func (*RedisService) GetMap

func (r *RedisService) GetMap(key string) map[string]interface{}

func (*RedisService) HDel

func (r *RedisService) HDel(key string, field ...string) error

func (*RedisService) HGet

func (r *RedisService) HGet(key, field string, result interface{})

func (*RedisService) HGetAsMap

func (r *RedisService) HGetAsMap(key, field string) map[string]interface{}

func (*RedisService) HMGet

func (r *RedisService) HMGet(key string, result interface{}, fields ...string)

func (*RedisService) HMGetAll

func (r *RedisService) HMGetAll(key string, result interface{})

result: *map[string]interface{}

func (*RedisService) HMSet

func (r *RedisService) HMSet(key string, kvs map[string]interface{}, secondsLifetime int64)

func (*RedisService) HSet

func (r *RedisService) HSet(key, field string, value interface{}, secondsLifetime int64)

func (*RedisService) LGet

func (r *RedisService) LGet(key string, index int, value interface{})

func (*RedisService) LGetAll

func (r *RedisService) LGetAll(key string, result interface{})

result : is a list point ,eg result = &a ; a is var a []Obj

func (*RedisService) LLen

func (r *RedisService) LLen(key string) int

func (*RedisService) LSet

func (r *RedisService) LSet(key string, objs interface{}, secondsLifetime int64)

objs : a list , eg. []xxx

func (*RedisService) Multi

func (r *RedisService) Multi()

Multi Unwatch Watch ... Exec/Discard

func (*RedisService) Now

func (r *RedisService) Now() int64

Now seconds

func (*RedisService) PingPong

func (r *RedisService) PingPong() bool

PingPong sends a ping and receives a pong, if no pong received then returns false and filled error

func (*RedisService) Publish

func (r *RedisService) Publish(channel string, msg interface{}) (int, error)

func (*RedisService) Select

func (r *RedisService) Select(db int)

func (*RedisService) Set

func (r *RedisService) Set(key interface{}, value interface{}, seconds int)

Get returns value, err by its key returns nil and a filled error if something bad happened.

func (*RedisService) SetJson

func (r *RedisService) SetJson(key string, value interface{}, secondsLifetime int64) (err error)

func (*RedisService) SetJsons

func (r *RedisService) SetJsons(keys []string, values interface{}, ttl int64)

func (*RedisService) Subscribe

func (r *RedisService) Subscribe(channel string) (*redis.PubSubConn, error)

func (*RedisService) TTL

func (r *RedisService) TTL(key string) int64

func (*RedisService) Time

func (r *RedisService) Time() (int64, int64)

func (*RedisService) Unwatch

func (r *RedisService) Unwatch()

func (*RedisService) Watch

func (r *RedisService) Watch(keys ...string)

func (*RedisService) WithTransaction

func (r *RedisService) WithTransaction(fn func(), watchKeys ...string) []interface{}

type RedisValue

type RedisValue struct {
	Value interface{}
}

func (RedisValue) Bool

func (r RedisValue) Bool() bool

func (RedisValue) Float64

func (r RedisValue) Float64() float64

func (RedisValue) Float64s

func (r RedisValue) Float64s() []float64

func (RedisValue) Int

func (r RedisValue) Int() int

func (RedisValue) Int64

func (r RedisValue) Int64() int64

func (RedisValue) Int64s

func (r RedisValue) Int64s() []int64

func (RedisValue) Ints

func (r RedisValue) Ints() []int

func (RedisValue) String

func (r RedisValue) String() string

func (RedisValue) Strings

func (r RedisValue) Strings() []string

type TimeHash

type TimeHash struct {
	Key                 string
	Ttl                 int //seconds
	HeartBeat           int //seconds
	Redis               *RedisService
	MaxNoHeartBeatCount int
}

func NewTimeHash

func NewTimeHash(redis *RedisService, key string, ttl, heartBeat, maxNoHeartBeatCount int) TimeHash

func (TimeHash) Del

func (t TimeHash) Del(key string) error

func (TimeHash) Get

func (t TimeHash) Get(key string) int

Get 返回key所对应的时间戳,无效<=0。如果存在则,刷新key的时间戳

func (TimeHash) GetAll

func (t TimeHash) GetAll() map[string]int

func (TimeHash) ListAll

func (t TimeHash) ListAll() []string

func (TimeHash) Set

func (t TimeHash) Set(key string)

Jump to

Keyboard shortcuts

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