redis

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2019 License: Apache-2.0 Imports: 4 Imported by: 0

README

使用说明:

config.ini 配置

[redis]
; 地址
host                = 192.168.0.213:16379
; 密码
pwd                 = 123456
; 数据库序号
db_index            = 0
; 最大空闲连接数
max_idle            = 1
; 最大连接数
max_active          = 100
; 空闲连接超时时间(秒)
idle_timeout        = 10
; 连接超时时间(秒)
conn_timeout        = 30

API使用

redisPool := InitRedisPool()

//String
_, err := redisPool.Set("key", "123")
if err != nil {
	log.Fatalln(err)
}
val, err := redisPool.Get("key")
if err != nil {
	log.Fatalln(err)
}
fmt.Println("key:", val)

//Hash
hash := map[string]string{
	"field1": "value1",
	"field2": "value2",
	"field3": "value3",
}
_, err = redisPool.Hmset("Hkey", hash)
if err != nil {
	log.Fatalln(err)
}
hVal, err := redisPool.Hmget("Hkey", []string{"field1", "field2"})
if err != nil {
	log.Fatalln(err)
}
for _, item := range hVal {
	fmt.Println(item)
}

命令参考: redisfans

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnPool

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

ConnPool redis连接池

func InitRedisPool

func InitRedisPool() *ConnPool

InitRedisPool 初始化

func (*ConnPool) Brpop

func (rc *ConnPool) Brpop(key string, timeoutSeconds int) ([]string, error)

Brpop for List

func (*ConnPool) Decr

func (rc *ConnPool) Decr(key string) (int64, error)

Decr for string

func (*ConnPool) DelKey

func (rc *ConnPool) DelKey(key string) (interface{}, error)

DelKey for key

func (*ConnPool) ExistsKey

func (rc *ConnPool) ExistsKey(key string) (bool, error)

ExistsKey for key

func (*ConnPool) ExpireKey

func (rc *ConnPool) ExpireKey(key string, seconds int) (interface{}, error)

ExpireKey for key

func (*ConnPool) Get

func (rc *ConnPool) Get(key string) (string, error)

Get for string

func (*ConnPool) GetErrNil added in v1.1.1

func (rc *ConnPool) GetErrNil(key string) (string, error)

GetErrNil for string

func (*ConnPool) Hdel

func (rc *ConnPool) Hdel(key string, field []string) (interface{}, error)

Hdel for Hash

func (*ConnPool) Hexists

func (rc *ConnPool) Hexists(key string, field string) (bool, error)

Hexists for Hash

func (*ConnPool) Hget

func (rc *ConnPool) Hget(key string, field string) (string, error)

Hget for Hash

func (*ConnPool) Hgetall

func (rc *ConnPool) Hgetall(key string) (map[string]string, error)

Hgetall for Hash

func (*ConnPool) Hlen

func (rc *ConnPool) Hlen(key string) (int, error)

Hlen for Hash

func (*ConnPool) Hmget

func (rc *ConnPool) Hmget(key string, field []string) ([]string, error)

Hmget for Hash

func (*ConnPool) Hmset

func (rc *ConnPool) Hmset(key string, fieldValue map[string]string) (interface{}, error)

Hmset for Hash

func (*ConnPool) Hset

func (rc *ConnPool) Hset(key string, field string, value string) (interface{}, error)

Hset for Hash

func (*ConnPool) Incr

func (rc *ConnPool) Incr(key string) (int64, error)

Incr for string

func (*ConnPool) Llen

func (rc *ConnPool) Llen(key string) (int, error)

Llen for List

func (*ConnPool) Lpush

func (rc *ConnPool) Lpush(key string, value []string) (interface{}, error)

Lpush for List

func (*ConnPool) LuaScriptZset added in v1.2.0

func (rc *ConnPool) LuaScriptZset(script, key string, score int64, member string) (interface{}, error)

LuaScriptZset for SortedSet

func (*ConnPool) Rpop

func (rc *ConnPool) Rpop(key string) (string, error)

Rpop for List

func (*ConnPool) Sadd

func (rc *ConnPool) Sadd(key string, member []string) (interface{}, error)

Sadd for Set

func (*ConnPool) Scard

func (rc *ConnPool) Scard(key string) (int, error)

Scard for Set

func (*ConnPool) Set

func (rc *ConnPool) Set(key string, value string) (interface{}, error)

Set for string

func (*ConnPool) SetExpire

func (rc *ConnPool) SetExpire(key string, value string, seconds int) (interface{}, error)

SetExpire for string

func (*ConnPool) Smembers

func (rc *ConnPool) Smembers(key string) ([]string, error)

Smembers for Set

func (*ConnPool) Srem

func (rc *ConnPool) Srem(key string, member []string) (interface{}, error)

Srem for Set

func (*ConnPool) Zadd

func (rc *ConnPool) Zadd(key string, score int64, member string) (interface{}, error)

Zadd for SortedSet

func (*ConnPool) Zcard

func (rc *ConnPool) Zcard(key string) (int, error)

Zcard for SortedSet

func (*ConnPool) Zrange

func (rc *ConnPool) Zrange(key string, start, stop int) ([]string, error)

Zrange for SortedSet

func (*ConnPool) Zrem

func (rc *ConnPool) Zrem(key string, member string) (interface{}, error)

Zrem for SortedSet

func (*ConnPool) Zremrangebyrank

func (rc *ConnPool) Zremrangebyrank(key string, start, stop int) (interface{}, error)

Zremrangebyrank for SortedSet

func (*ConnPool) Zremrangebyscore

func (rc *ConnPool) Zremrangebyscore(key string, min, max int64) (interface{}, error)

Zremrangebyscore for SortedSet

func (*ConnPool) Zrevrange

func (rc *ConnPool) Zrevrange(key string, start, stop int) ([]string, error)

Zrevrange for SortedSet

Jump to

Keyboard shortcuts

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