redis

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNil = redis.ErrNil

	DefaultConf = &ClientConf{
		Address:        "127.0.0.1:6379",
		ConnectTimeout: time.Second * 30,
	}
)
View Source
var (
	ExistErr = fmt.Errorf("key already exist")
)
View Source
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) DEL

func (c *Client) DEL(key string) error

DEL delete key , is equal to Expire(key,0)

func (*Client) Do

func (c *Client) Do(commandName string, args ...interface{}) (reply interface{}, err error)

Do sends a command to the server and returns the received reply.

func (*Client) Exists

func (c *Client) Exists(key string) (bool, error)

Exists return key existence

func (*Client) Expire

func (c *Client) Expire(key string, seconds int) (err error)

Expire set expire, set seconds=0 will delete the key

func (*Client) FlushAll added in v0.1.9

func (c *Client) FlushAll() error

Rename rename the key

func (*Client) Get

func (c *Client) Get(key string) (interface{}, error)

GetString string get string

func (*Client) GetBytes

func (c *Client) GetBytes(key string) ([]byte, error)

func (*Client) GetConn

func (c *Client) GetConn() redis.Conn

Get return redis conn

func (*Client) GetCtxConn

func (c *Client) GetCtxConn(ctx context.Context) (redis.Conn, error)

GetCtxConn return redis conn with provide context

func (*Client) GetInt

func (c *Client) GetInt(key string) (int, error)

GetInt string get int

func (*Client) GetString

func (c *Client) GetString(key string) (string, error)

GetString string get string

func (*Client) HDel

func (c *Client) HDel(key, itemKey string) (err error)

HDel hash delete key-item

func (*Client) HExists

func (c *Client) HExists(key, itemKey string) (bool, error)

HExists select hash key-item's existence

func (*Client) HGet

func (c *Client) HGet(userKey, itemKey string) (interface{}, error)

HGet hash get interface

func (*Client) HGetBool

func (c *Client) HGetBool(userKey, itemKey string) (bool, error)

HGetBool hash get bool

func (*Client) HGetBytes

func (c *Client) HGetBytes(userKey, itemKey string) ([]byte, error)

HGetBytes hash get []byte

func (*Client) HGetFloat64

func (c *Client) HGetFloat64(userKey, itemKey string) (float64, error)

HGetFloat64 hash get float64

func (*Client) HGetInt

func (c *Client) HGetInt(userKey, itemKey string) (int, error)

HGetInt get int

func (*Client) HGetInt64

func (c *Client) HGetInt64(userKey, itemKey string) (int64, error)

HGetInt64 get int64

func (*Client) HGetInt64Map

func (c *Client) HGetInt64Map(userKey, itemKey string) (map[string]int64, error)

HGetInt64Map hash get int64 map

func (*Client) HGetIntMap

func (c *Client) HGetIntMap(userKey, itemKey string) (map[string]int, error)

HGetIntMap hash get int map

func (*Client) HGetInts

func (c *Client) HGetInts(userKey, itemKey string) ([]int, error)

HGetInts hash get ints

func (*Client) HGetString

func (c *Client) HGetString(userKey, itemKey string) (string, error)

HGetString hash get string

func (*Client) HGetStringMap

func (c *Client) HGetStringMap(userKey, itemKey string) (map[string]string, error)

HGetStringMap hash get string map

func (*Client) HGetStrings

func (c *Client) HGetStrings(userKey, itemKey string) ([]string, error)

HGetStrings hash get strings

func (*Client) HSet

func (c *Client) HSet(key, itemKey string, item interface{}) (err error)

HSet hash set

func (*Client) NewPubSub

func (c *Client) NewPubSub() *PubSub

NewSession return redips PubSub

func (*Client) NewSession

func (c *Client) NewSession() *Session

NewSession return redis session

func (*Client) Ping

func (c *Client) Ping() (err error)

Ping check the redis status

func (*Client) Rename

func (c *Client) Rename(key string, newKeyName string) error

Rename rename the key

func (*Client) SAdd

func (c *Client) SAdd(key string, args ...interface{}) (count int64, err error)

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) SCard

func (c *Client) SCard(key string) (int64, error)

SCard return the count of key set

func (*Client) SMembers

func (c *Client) SMembers(key string) ([]interface{}, error)

SMembers return all members of key set

func (*Client) SMembersInts

func (c *Client) SMembersInts(key string) (reply []int, err error)

SMembersInts return all int members of key set

func (*Client) SMembersStrings

func (c *Client) SMembersStrings(key string) (reply []string, err error)

SMembersStrings return all string members of key set

func (*Client) SRem

func (c *Client) SRem(key string, member interface{}) (err error)

SRem remove the member of key set

func (*Client) Set

func (c *Client) Set(key, value interface{}) (err error)

Set store string

func (*Client) SetNX

func (c *Client) SetNX(key string, value interface{}, seconds int) (err error)

SetNX set unique string type value

func (*Client) Type

func (c *Client) Type(key string) (Type, error)

Type return the type of the key

func (*Client) ZAdd added in v0.1.9

func (c *Client) ZAdd(key string, score int, member string) (count int64, err error)

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

func (c *Client) ZAddWithIncr(key string, score int, member string) (resultScore int64, err error)

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) ZRange added in v0.1.9

func (c *Client) ZRange(key string, start, end int) ([]string, error)

ZRange list members from start to end

func (*Client) ZRangeWithScore added in v0.1.9

func (c *Client) ZRangeWithScore(key string, start, end int) ([]string, error)

ZRange list members from start to end

func (*Client) ZRank added in v0.1.9

func (c *Client) ZRank(key string, member string) (int64, error)

ZRank return the index of the member

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 Pong

type Pong struct {
	Data string
}

Pong represents a pubsub pong notification.

type PubSub

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

PubSub publish and subscribe

func (PubSub) Close

func (ps PubSub) Close() error

Close closes the connection.

func (PubSub) PSubscribe

func (ps PubSub) PSubscribe(channel ...interface{}) error

PSubscribe subscribes the connection to the given patterns.

func (PubSub) PUnsubscribe

func (ps PubSub) PUnsubscribe(channel ...interface{}) error

PUnsubscribe unsubscribes the connection from the given patterns, or from all of them if none is given.

func (PubSub) Ping

func (ps PubSub) Ping(data string) error

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) Publish

func (ps *PubSub) Publish(channel string, arg interface{}) (int, error)

Publish publish messages to specified channel and return subscribe

func (PubSub) Receive

func (ps PubSub) Receive() (Message, error)

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

func (ps PubSub) ReceiveWithTimeout(timeout time.Duration) (Message, error)

ReceiveWithTimeout is like Receive, but it allows the application to override the connection's default timeout.

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(channel ...interface{}) error

Subscribe subscribes the connection to the specified channels.

func (PubSub) Unsubscribe

func (ps PubSub) Unsubscribe(channel ...interface{}) error

Unsubscribe unsubscribes the connection from the given channels, or from all of them if none is given.

type Session

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

Session session

func (*Session) Begin

func (s *Session) Begin() (err error)

Begin init nums and pool

func (*Session) Close

func (s *Session) Close() error

Close clear conn read buf and close net.conn

func (*Session) Commit

func (s *Session) Commit() error

Commit commit write buf to redis server

func (*Session) Exec

func (s *Session) Exec(commandName string, args ...interface{}) (err error)

Exec nums++ and fill in redis.conn.write buf

func (*Session) Receive

func (s *Session) Receive() (interface{}, error)

Receive receive data from redis.conn.read buf

type Type

type Type string
const (
	TypeNone   Type = "none"
	TypeString Type = "string"
	TypeList   Type = "list"
	TypeSet    Type = "set"
	TypeZSet   Type = "zset"
	TypeHash   Type = "hash"
	TypeStream Type = "stream"
)

Jump to

Keyboard shortcuts

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