Documentation ¶
Index ¶
- Constants
- Variables
- func BytesMap(result interface{}, err error) (map[string][]byte, error)
- func Get(key string) (value interface{})
- func NewError(msg string) error
- func Range(handler func(key string, pool Pool, group Group) bool)
- func Set(key string, value interface{})
- func SetGroup(key string, options ...GroupOption) (err error)
- func SetPool(key string, option Option)
- func SetPoolByJson(key string, jsonStr string) (err error)
- func String(reply interface{}, err error) (string, error)
- type Cmd
- type Conf
- type ConfOption
- type GedisError
- type Group
- type GroupOption
- type Handler
- type Item
- type Location
- type Log
- type Msg
- type Multi
- type Option
- type Pong
- type Pool
- type Position
- type SubConn
- type Subscription
Constants ¶
View Source
const ( Transaction = 1 Pipeline = 2 )
View Source
const ( Ok = `OK` Success = 1 )
View Source
const (
DefaultNotifyPattern = `KA$`
)
Variables ¶
View Source
var ( ErrKeyFormat = NewError(`key format error`) ErrKeyList = NewError(`key list is empty`) )
View Source
var ( Error = base.Error Debug = base.Debug )
View Source
var ( PipeMulti = func() Multi { m := multiPool.Get().(*multi) m.kind = Pipeline return m } TransMulti = func() Multi { m := multiPool.Get().(*multi) m.kind = Transaction return m } ReleaseMulti = func(m Multi) { m.Reset() multiPool.Put(m) } )
View Source
var DefaultLocalCache sync.Map
View Source
var (
ErrOptionEmpty = errors.New(`redis option empty`)
)
View Source
var (
ErrUnKnownSubMsg = errors.New(`unknown pubsub notification`)
)
Functions ¶
func SetGroup ¶ added in v1.0.3
func SetGroup(key string, options ...GroupOption) (err error)
func SetPoolByJson ¶ added in v1.0.3
Types ¶
type Conf ¶ added in v1.0.6
type Conf struct {
// contains filtered or unexported fields
}
func NewConf ¶ added in v1.0.6
func NewConf(option ConfOption) (c *Conf, err error)
func (*Conf) SetKeyspaceNotify ¶ added in v1.0.6
type ConfOption ¶ added in v1.0.6
type ConfOption struct { Option Option `json:"option" yaml:"option"` Prefix string `json:"prefix" yaml:"prefix"` KeyList []string `json:"key_list" yaml:"key_list"` SyncIntervalSecond int64 `json:"sync_interval_second" yaml:"sync_interval_second"` SyncPageSize int `json:"sync_page_size" yaml:"sync_page_size"` }
type GedisError ¶ added in v1.0.6
type GedisError struct {
// contains filtered or unexported fields
}
func (*GedisError) Error ¶ added in v1.0.6
func (ge *GedisError) Error() string
func (*GedisError) Is ¶ added in v1.0.6
func (ge *GedisError) Is(target error) bool
type Group ¶
type GroupOption ¶
type Item ¶
type Item struct { CreatedAt int64 `json:"created_at"` UpdatedAt int64 `json:"updated_at"` UpdatedCount int64 `json:"updated_count"` Value []byte `json:"value"` }
Item 缓存Item
type Multi ¶
type Multi interface { //-----------------Key-------------------------- Del(keys ...interface{}) Multi Exists(key interface{}) Multi Expire(key interface{}, second int64) Multi ExpireAt(key interface{}, unixTime int64) Multi Ttl(key interface{}) Multi Persist(key interface{}) Multi Keys(pattern string) Multi Dump(key string) Multi Restore(key string, pttl int64, serializedValue string) Multi Move(key string, db int) Multi RandomKey() Multi ReName(key string, newKey string) Multi ReNameNx(key string, newKey string) Multi Type(key string) Multi //-----------------String-------------------------- Append(key string, value interface{}) Multi Get(key string) Multi MGet(keys ...string) Multi MSet(key1 string, value1 interface{}, keyValues ...interface{}) Multi MSetByMap(keyValues map[string]interface{}) Multi Set(key string, value interface{}, args ...interface{}) Multi SetEx(key string, seconds int, value interface{}) Multi SetNx(key string, value interface{}) Multi GetSet(key string, value interface{}) Multi Incr(key string) Multi Decr(key string) Multi IncrBy(key string, increment int) Multi DecrBy(key string, decrement int) Multi IncrByFloat(key string, increment float64) Multi SetRange(key string, offset int, val string) Multi GetRange(key string, start, end int) Multi SetBit(key string, offset int, bit int8) Multi GetBit(key string, offset int) Multi BitCount(key string, args ...interface{}) Multi //-----------------Hash-------------------------- HSet(key string, field string, value interface{}) Multi HSetNx(key string, field string, value interface{}) Multi HGet(key string, field string) Multi HMSet(key string, field1 string, value1 interface{}, args ...interface{}) Multi HMSetMap(key string, keyValues map[string]interface{}) Multi HMGet(key string, fields ...string) Multi HGetAll(key string) Multi HDel(key string, fields ...string) Multi HExists(key string, field string) Multi HIncrBy(key string, field string, increment int) Multi HIncrByFloat(key string, field string, increment float64) Multi HKeys(key string) Multi HVals(key string) Multi HLen(key string) Multi //-----------------List-------------------------- LLen(key string) Multi LPush(key string, values ...interface{}) Multi LPushX(key string, value interface{}) Multi LPop(key string) Multi LIndex(key string, index int) Multi LRange(key string, start, stop int) Multi LSet(key string, index int, value interface{}) Multi LTrim(key string, start, stop int) Multi RPush(key string, values ...interface{}) Multi RPushX(key string, value interface{}) Multi RPop(key string) Multi //--------------------Set--------------------------- SAdd(key string, members ...interface{}) Multi SMembers(key string) Multi SIsMember(key string, member interface{}) Multi SCard(key string) Multi SPop(key string) Multi SRandMember(key string, count int) Multi SRem(key string, members ...interface{}) Multi SMove(sourceSetKey, destinationSetKey string, member interface{}) Multi SDiff(keys ...interface{}) Multi SDiffStore(destinationSetKey string, keys ...string) Multi SInter(keys ...interface{}) Multi SInterStore(destinationSetKey string, keys ...string) Multi SUnion(keys ...interface{}) Multi SUnionStore(destinationSetKey string, keys ...string) Multi //--------------------ZSet--------------------------- ZAdd(key string, score, value interface{}, scoreAndValues ...interface{}) Multi ZAddMap(key string, membersMap map[string]interface{}) Multi ZCard(key string) Multi ZCount(key string, minScore, maxScore interface{}) Multi ZIncrBy(key string, increment interface{}, member string) Multi ZRange(key string, startIndex, stopIndex int) Multi ZRevRange(key string, startIndex, stopIndex int) Multi ZRangeWithScore(key string, startIndex, stopIndex int) Multi ZRevRangeWithScore(key string, startIndex, stopIndex int) Multi ZRangeByScore(key string, minScore, maxScore interface{}, offset, limit int) Multi ZRevRangeByScore(key string, maxScore, minScore interface{}, offset, limit int) Multi ZRangeByScoreWithScore(key string, minScore, maxScore interface{}, offset, limit int) Multi ZRevRangeByScoreWithScore(key string, maxScore, minScore interface{}, offset, limit int) Multi ZRank(key, member string) Multi ZRevRank(key, member string) Multi ZScore(key, member string) Multi ZRem(key string, members ...interface{}) Multi ZRemRangeByRank(key string, startIndex, stopIndex int) Multi //--------------------ZSet--------------------------- GeoAdd(key string, longitude, latitude float64, member interface{}, args ...interface{}) Multi GeoHash(key string, members ...interface{}) Multi GeoDel(key string, members ...interface{}) Multi GeoDist(key string, member1, member2 interface{}, unit string) Multi GeoPos(key string, members ...interface{}) Multi GeoRadius(key string, longitude, latitude float64, radius interface{}, unit string, count int, sort string) Multi GeoRadiusByMember(key string, member interface{}, radius interface{}, unit string, count int, sort string) Multi Reset() Kind() uint8 CmdList() []Cmd }
type Option ¶
type Option struct { Host string `yaml:"host" json:"host"` Port int `yaml:"port" json:"port"` Auth string `yaml:"auth" json:"auth"` Db uint8 `yaml:"db" json:"db"` MaxConnLifetimeSecond int `yaml:"maxConnLifetimeSecond" json:"maxConnLifetimeSecond"` IdleTimeoutSecond int `yaml:"idleTimeoutSecond" json:"idleTimeoutSecond"` MaxIdle int `yaml:"maxIdle" json:"maxIdle"` MaxActive int `yaml:"maxActive" json:"maxActive"` Wait bool `yaml:"wait" json:"wait"` //单位ms ConnectTimeout int `yaml:"connectTimeout" json:"connectTimeout"` //单位ms ReadTimeout int `yaml:"readTimeout" json:"readTimeout"` //单位ms WriteTimeout int `yaml:"writeTimeout" json:"writeTimeout"` //节点索引 Index int `yaml:"index" json:"index"` }
func DefaultOption ¶ added in v1.0.3
func DefaultOption() Option
type Pool ¶
type Pool interface { base.CanHash ActiveCount() (num int) IdleCount() (num int) Stats() redigo.PoolStats Close() (err error) Do(cmd string, args ...interface{}) (reply interface{}, err error) //-----------------Key-------------------------- Del(keys ...interface{}) (delNum int, err error) Exists(key interface{}) (exists bool, err error) Expire(key interface{}, second int64) (success int, err error) ExpireAt(key interface{}, unixTime int64) (success int, err error) Ttl(key interface{}) (second int64, err error) Persist(key interface{}) (success int, err error) Scan(cursor int, match string, count int) (newCursor int, keys []string, err error) Keys(pattern string) (keys []string, err error) Dump(key string) (serializedValue string, err error) Restore(key string, pttl int64, serializedValue string) (ok bool, err error) Move(key string, db int) (success int, err error) RandomKey() (key string, err error) ReName(key string, newKey string) (ok bool, err error) ReNameNx(key string, newKey string) (success int, err error) Type(key string) (t string, err error) //-----------------String-------------------------- Append(key string, value interface{}) (strLength int, err error) Get(key string) (val string, err error) GetBytes(key string) (val []byte, err error) MGet(keys ...string) (values []string, err error) MGetMap(keys ...string) (keyValue map[string]string, err error) MGetBytesMap(keys ...string) (keyValue map[string][]byte, err error) MSet(key1 string, value1 interface{}, keyValues ...interface{}) (ok bool, err error) MSetByMap(keyValues map[string]interface{}) (ok bool, err error) Set(key string, value interface{}, args ...interface{}) (ok bool, err error) SetEx(key string, seconds int, value interface{}) (ok bool, err error) SetNx(key string, value interface{}) (ok int, err error) GetSet(key string, value interface{}) (oldValue string, err error) Incr(key string) (val int64, err error) Decr(key string) (val int64, err error) IncrBy(key string, increment int) (val int64, err error) DecrBy(key string, decrement int) (val int64, err error) IncrByFloat(key string, increment float64) (val float64, err error) SetRange(key string, offset int, val string) (strLength int, err error) GetRange(key string, start, end int) (val string, err error) SetBit(key string, offset int, bit int8) (oldBit int, err error) GetBit(key string, offset int) (bit int, err error) BitCount(key string, args ...interface{}) (num int, err error) //-----------------Hash-------------------------- HSet(key string, field string, value interface{}) (isNew int, err error) HSetNx(key string, field string, value interface{}) (ok int, err error) HGet(key string, field string) (value string, err error) HMSet(key string, field1 string, value1 interface{}, args ...interface{}) (ok bool, err error) HMSetMap(key string, keyValues map[string]interface{}) (ok bool, err error) HMGet(key string, fields ...string) (values []string, err error) HMGetMap(key string, fields ...string) (keyValues map[string]string, err error) HGetAll(key string) (keyValues map[string]string, err error) HGetAllBytes(key string) (keyValues map[string][]byte, err error) HDel(key string, fields ...string) (delNum int, err error) HExists(key string, field string) (exists bool, err error) HIncrBy(key string, field string, increment int) (val int64, err error) HIncrByFloat(key string, field string, increment float64) (val float64, err error) HKeys(key string) (fields []string, err error) HVals(key string) (values []string, err error) HLen(key string) (length int, err error) //-----------------List-------------------------- LLen(key string) (listLength int, err error) LPush(key string, values ...interface{}) (listLength int, err error) LPushX(key string, value interface{}) (listLength int, err error) LPop(key string) (value string, err error) LIndex(key string, index int) (value string, err error) LRange(key string, start, stop int) (values []string, err error) LSet(key string, index int, value interface{}) (ok bool, err error) LTrim(key string, start, stop int) (ok bool, err error) RPush(key string, values ...interface{}) (listLength int, err error) RPushX(key string, value interface{}) (listLength int, err error) RPop(key string) (value string, err error) //--------------------Set--------------------------- SAdd(key string, members ...interface{}) (addNum int, err error) SMembers(key string) (members []string, err error) SIsMember(key string, member interface{}) (exists bool, err error) SCard(key string) (count int, err error) SPop(key string) (member string, err error) SRandMember(key string, count int) (members []string, err error) SRem(key string, members ...interface{}) (removeNum int, err error) SMove(sourceSetKey, destinationSetKey string, member interface{}) (success int, err error) SDiff(keys ...interface{}) (members []string, err error) SDiffStore(destinationSetKey string, keys ...string) (memberCount int, err error) SInter(keys ...interface{}) (members []string, err error) SInterStore(destinationSetKey string, keys ...string) (memberCount int, err error) SUnion(keys ...interface{}) (members []string, err error) SUnionStore(destinationSetKey string, keys ...string) (memberCount int, err error) SScan(key string, cursor int, match string, count int) (newCursor int, keys []string, err error) //--------------------ZSet--------------------------- ZAdd(key string, score, value interface{}, scoreAndValues ...interface{}) (createNum int, err error) ZAddMap(key string, membersMap map[string]interface{}) (createNum int, err error) ZCard(key string) (count int, err error) ZCount(key string, minScore, maxScore interface{}) (count int, err error) ZIncrBy(key string, increment interface{}, member string) (newScore string, err error) ZRange(key string, startIndex, stopIndex int) (members []string, err error) ZRevRange(key string, startIndex, stopIndex int) (members []string, err error) ZRangeWithScore(key string, startIndex, stopIndex int) (members map[string]string, err error) ZRevRangeWithScore(key string, startIndex, stopIndex int) (members map[string]string, err error) ZRangeByScore(key string, minScore, maxScore interface{}, offset, limit int) (members []string, err error) ZRevRangeByScore(key string, maxScore, minScore interface{}, offset, limit int) (members []string, err error) ZRangeByScoreWithScore(key string, minScore, maxScore interface{}, offset, limit int) (members map[string]string, err error) ZRevRangeByScoreWithScore(key string, maxScore, minScore interface{}, offset, limit int) (members map[string]string, err error) ZRank(key, member string) (rankIndex int, err error) ZRevRank(key, member string) (rankIndex int, err error) ZScore(key, member string) (score string, err error) ZRem(key string, members ...interface{}) (removeNum int, err error) ZRemRangeByRank(key string, startIndex, stopIndex int) (removeNum int, err error) ZScan(key string, cursor int, match string, count int) (newCursor int, keys []string, err error) //----------------------Geo----------------------------- GeoAdd(key string, longitude, latitude float64, member interface{}, args ...interface{}) (createNum int, err error) GeoHash(key string, members ...interface{}) (hashList []string, err error) GeoDel(key string, members ...interface{}) (removeNum int, err error) GeoDist(key string, member1, member2 interface{}, unit string) (distance string, err error) GeoPos(key string, members ...interface{}) (positionList []Position, err error) GeoRadius(key string, longitude, latitude float64, radius interface{}, unit string, count int, sort string) (locationList []Location, err error) GeoRadiusByMember(key string, member interface{}, radius interface{}, unit string, count int, sort string) (locationList []Location, err error) //--------------------Pub/Sub--------------------------- Publish(channel string, msg string) (receiveNum int, err error) PubSubChannels(pattern string) (channels []string, err error) //--------------------Script--------------------------- EvalOrSha(script *redigo.Script, keysAndArgs ...interface{}) (reply interface{}, err error) EvalOrSha4Int64(script *redigo.Script, keysAndArgs ...interface{}) (res int64, err error) EvalOrSha4String(script *redigo.Script, keysAndArgs ...interface{}) (res string, err error) //--------------------Transaction--------------------------- Exec(multi Multi) (values []interface{}, err error) //--------------------Lock/Limit/Cache--------------------------- Acquire(key string, timeoutSecond int) (token int64, err error) Release(key string, token int64) (ok bool, err error) LevelCache(localCache *sync.Map, key string, current, timeoutSecond int64, handler Handler) (value []byte, err error) CacheGet(key string, current, timeoutSecond int64, handler Handler) (value []byte, err error) CacheGetItem(key string, current, timeoutSecond int64, handler Handler) (item Item, err error) CacheRemove(key string) (ok bool, err error) GetToken(key string, current int64, capacity, rate, reqNum, keyTimeoutSecond int) (ok bool, err error) SecondLimitByToken(key string, limit int, reqNum int) (ok bool, err error) SecondLimitByTime(key string, limit int, reqNum int) (ok bool, err error) MinuteLimitByTime(key string, limit int, reqNum int) (ok bool, err error) HourLimitByTime(key string, limit int, reqNum int) (ok bool, err error) DayLimitByTime(key string, limit int, reqNum int) (ok bool, err error) //-----------------Server-------------------------- ClientList() (clients []string, err error) ConfigGet(pattern string) (conf map[string]string, err error) ConfigSet(param string, value interface{}) (ok bool, err error) }
func NewPoolWithJson ¶ added in v1.0.3
NewPoolWithJson 实例化Pool
type SubConn ¶
type SubConn interface { Close() error Subscribe(channels ...interface{}) error SubscribeChannel(ctx context.Context, size int, channels ...interface{}) (ch <-chan interface{}, err error) PSubscribe(channels ...interface{}) error PSubscribeChannel(ctx context.Context, size int, channels ...interface{}) (ch <-chan interface{}, err error) Unsubscribe(channels ...interface{}) error PUnsubscribe(channels ...interface{}) error Ping(data string) error Receive() interface{} ReceiveWithTimeout(timeout time.Duration) interface{} }
func NewSubConn ¶
type Subscription ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.