Documentation ¶
Index ¶
- Variables
- type Client
- func (c *Client) DEL(key string) error
- func (c *Client) Do(commandName string, args ...interface{}) (reply interface{}, err error)
- func (c *Client) Exists(key string) (bool, error)
- func (c *Client) Expire(key string, seconds int) (err error)
- func (c *Client) FlushAll() error
- func (c *Client) Get(key string) (interface{}, error)
- func (c *Client) GetBytes(key string) ([]byte, error)
- func (c *Client) GetConn() redis.Conn
- func (c *Client) GetCtxConn(ctx context.Context) (redis.Conn, error)
- func (c *Client) GetInt(key string) (int, error)
- func (c *Client) GetString(key string) (string, error)
- func (c *Client) HDel(key, itemKey string) (err error)
- func (c *Client) HExists(key, itemKey string) (bool, error)
- func (c *Client) HGet(userKey, itemKey string) (interface{}, error)
- func (c *Client) HGetBool(userKey, itemKey string) (bool, error)
- func (c *Client) HGetBytes(userKey, itemKey string) ([]byte, error)
- func (c *Client) HGetFloat64(userKey, itemKey string) (float64, error)
- func (c *Client) HGetInt(userKey, itemKey string) (int, error)
- func (c *Client) HGetInt64(userKey, itemKey string) (int64, error)
- func (c *Client) HGetInt64Map(userKey, itemKey string) (map[string]int64, error)
- func (c *Client) HGetIntMap(userKey, itemKey string) (map[string]int, error)
- func (c *Client) HGetInts(userKey, itemKey string) ([]int, error)
- func (c *Client) HGetString(userKey, itemKey string) (string, error)
- func (c *Client) HGetStringMap(userKey, itemKey string) (map[string]string, error)
- func (c *Client) HGetStrings(userKey, itemKey string) ([]string, error)
- func (c *Client) HSet(key, itemKey string, item interface{}) (err error)
- func (c *Client) NewPubSub() *PubSub
- func (c *Client) NewSession() *Session
- func (c *Client) Ping() (err error)
- func (c *Client) Rename(key string, newKeyName string) error
- func (c *Client) SAdd(key string, args ...interface{}) (count int64, err error)
- func (c *Client) SCard(key string) (int64, error)
- func (c *Client) SMembers(key string) ([]interface{}, error)
- func (c *Client) SMembersInts(key string) (reply []int, err error)
- func (c *Client) SMembersStrings(key string) (reply []string, err error)
- func (c *Client) SRem(key string, member interface{}) (err error)
- func (c *Client) Set(key, value interface{}) (err error)
- func (c *Client) SetNX(key string, value interface{}, seconds int) (err error)
- func (c *Client) Type(key string) (Type, error)
- func (c *Client) ZAdd(key string, score int, member string) (count int64, err error)
- func (c *Client) ZAddWithIncr(key string, score int, member string) (resultScore int64, err error)
- func (c *Client) ZRange(key string, start, end int) ([]string, error)
- func (c *Client) ZRangeWithScore(key string, start, end int) ([]string, error)
- func (c *Client) ZRank(key string, member string) (int64, error)
- type ClientConf
- type Message
- type Pong
- type PubSub
- func (ps PubSub) Close() error
- func (ps PubSub) PSubscribe(channel ...interface{}) error
- func (ps PubSub) PUnsubscribe(channel ...interface{}) error
- func (ps PubSub) Ping(data string) error
- func (ps *PubSub) Publish(channel string, arg interface{}) (int, error)
- func (ps PubSub) Receive() (Message, error)
- func (ps PubSub) ReceiveWithTimeout(timeout time.Duration) (Message, error)
- func (ps *PubSub) Subscribe(channel ...interface{}) error
- func (ps PubSub) Unsubscribe(channel ...interface{}) error
- type Session
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( ErrNil = redis.ErrNil DefaultConf = &ClientConf{ Address: "127.0.0.1:6379", ConnectTimeout: time.Second * 30, } )
var (
ExistErr = fmt.Errorf("key already exist")
)
var (
NotExistErr = fmt.Errorf("key not exist")
)
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client redis client
func NewClient ¶
func NewClient(conf *ClientConf) *Client
NewClient before connect will ping , default ping timeout is a minute
func UniqueClient ¶
func UniqueClient(conf *ClientConf) *Client
func (*Client) GetCtxConn ¶
GetCtxConn return redis conn with provide context
func (*Client) HGetFloat64 ¶
HGetFloat64 hash get float64
func (*Client) HGetInt64Map ¶
HGetInt64Map hash get int64 map
func (*Client) HGetIntMap ¶
HGetIntMap hash get int map
func (*Client) HGetString ¶
HGetString hash get string
func (*Client) HGetStringMap ¶
HGetStringMap hash get string map
func (*Client) HGetStrings ¶
HGetStrings hash get strings
func (*Client) SAdd ¶
SAdd add key-value and return the count of success notice: if you want use slice or array , you can only use int, int64, float64, string slice or array SAdd(key, 1,2,3,4,5,6) SAdd(key, []int{1,2,3,4,5,6}) SAdd(key, []string{"1","2","3","4","5","6"})
func (*Client) SMembersInts ¶
SMembersInts return all int members of key set
func (*Client) SMembersStrings ¶
SMembersStrings return all string members of key set
func (*Client) ZAdd ¶ added in v0.1.9
ZADD add score and member to sorted set if already exist, return count = 0 and update member's score else return count = 1
func (*Client) ZAddWithIncr ¶ added in v0.1.9
ZAddWithIncr incr score to member return count = origin score + incr score eg. already exist member = a, score = 10
zdd [key] incr 10 a
return count = 20 now member = a , score = 20
func (*Client) ZRangeWithScore ¶ added in v0.1.9
ZRange list members from start to end
type ClientConf ¶
type ClientConf struct { Address string Password string DB int ConnectTimeout time.Duration ReadTimeout time.Duration WriteTimeout time.Duration KeepAlive time.Duration // Maximum number of idle connections in the pool. MaxIdle int // Maximum number of connections allocated by the pool at a given time. // When zero, there is no limit on the number of connections in the pool. MaxActive int // Close connections after remaining idle for this duration. If the value // is zero, then idle connections are not closed. Applications should set // the timeout to a value less than the server's timeout. IdleTimeout time.Duration // If Wait is true and the pool is at the MaxActive limit, then Get() waits // for a connection to be returned to the pool before returning. Wait bool // Close connections older than this duration. If the value is zero, then // the pool does not close connections based on age. MaxConnLifetime time.Duration }
ClientConf redis client config
func (*ClientConf) DialOptions ¶
func (conf *ClientConf) DialOptions() []redis.DialOption
DialOptions return the dial options
type Message ¶
type Message struct { //Kind is "subscribe", "unsubscribe", "psubscribe" or "punsubscribe" Kind string //The originating channel. Channel string //The message data. Data []byte }
Message represents a message notification.
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub publish and subscribe
func (PubSub) PSubscribe ¶
PSubscribe subscribes the connection to the given patterns.
func (PubSub) PUnsubscribe ¶
PUnsubscribe unsubscribes the connection from the given patterns, or from all of them if none is given.
func (PubSub) Ping ¶
Ping sends a PING to the server with the specified data.
The connection must be subscribed to at least one channel or pattern when calling this method.
func (PubSub) Receive ¶
Receive returns a pushed message as a Subscription, Message, Pong or error. The return value is intended to be used directly in a type switch as illustrated in the PubSubConn example.
func (PubSub) ReceiveWithTimeout ¶
ReceiveWithTimeout is like Receive, but it allows the application to override the connection's default timeout.
func (PubSub) Unsubscribe ¶
Unsubscribe unsubscribes the connection from the given channels, or from all of them if none is given.