redis

package
v0.6.8 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: MIT Imports: 4 Imported by: 0

README

redis 工具使用

第一步:初始化链接

比如放在 init()方法中,初始化一次

    
func init(){
	conf := RDSConfig{
		Host:      "192.168.0.197",
		Port:      6379,
		Password:  "123456",
		MaxIdle:   50,
		MaxActive: 10000,
		DB:        1,
	}

	err := InitRDSClient(&conf)
	if err != nil {
		fmt.Println("连接失败:", err)
	}
}

操作redis

	//get rds common
	redis := GetRDSCommon()
	key := "token:1"
        
    // SetString
	_, err = redis.SetString(key, "abcdef1xd0r1jdkf")
	if err != nil {
		t.Fatal(err)
	}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitRDSClient

func InitRDSClient(rdc *RDSConfig) (err error)

InitRDSClient init config

Types

type RDSCommon

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

func GetRDSCommon

func GetRDSCommon() *RDSCommon

GetRDSCommon return redis func

func (*RDSCommon) AddSet added in v0.1.9

func (m *RDSCommon) AddSet(key string, values []string) error

AddSet

func (*RDSCommon) AddZSet added in v0.1.0

func (m *RDSCommon) AddZSet(key string, score float64, value []byte) (err error)

AddZSet 添加单个ZST

func (*RDSCommon) DEL

func (m *RDSCommon) DEL(key string) (int64, error)

DEL 删除某个Key

func (*RDSCommon) DelZSetMember added in v0.1.0

func (m *RDSCommon) DelZSetMember(key string, member interface{}) error

DelZSetMember 删除zset成员

func (*RDSCommon) Exists

func (m *RDSCommon) Exists(key string) (bool, error)

Exist key是否正在

func (*RDSCommon) GetBit

func (m *RDSCommon) GetBit(key string, offset int64) (int, error)

get bit

func (*RDSCommon) GetHashAll

func (m *RDSCommon) GetHashAll(key string, obj interface{}) (err error)

GetHash get hash all to obj

func (*RDSCommon) GetHashAll2Map added in v0.5.6

func (m *RDSCommon) GetHashAll2Map(key string) (map[string]string, error)

GetHash get hash all to map

func (*RDSCommon) GetHashInt

func (m *RDSCommon) GetHashInt(key string, v interface{}) (int64, error)

GetHashInt 获取hash里某个int值

func (*RDSCommon) GetHashString

func (m *RDSCommon) GetHashString(key string, v interface{}) (string, error)

GetHashString 获取hash里某个int值

func (*RDSCommon) GetHashValue added in v0.5.7

func (m *RDSCommon) GetHashValue(key string) (data []string, err error)

GetHashValue get hash all

func (*RDSCommon) GetHashfields added in v0.5.6

func (m *RDSCommon) GetHashfields(key string, fields []string) ([]string, error)

HMGET key field [field ...] 返回哈希表 key 中,一个或多个给定域的值。 如果给定的域不存在于哈希表,那么返回一个 nil 值。

func (*RDSCommon) GetInt64

func (m *RDSCommon) GetInt64(key string) (v int64, err error)

GetInt64 取 int64

func (*RDSCommon) GetList added in v0.1.9

func (m *RDSCommon) GetList(key string) (data []string, err error)

GetList

func (*RDSCommon) GetSet added in v0.1.0

func (m *RDSCommon) GetSet(key string, v interface{}) (interface{}, error)

GetSet 设置指定 key 的值,并返回 key 的旧值。

func (*RDSCommon) GetSetData added in v0.1.9

func (m *RDSCommon) GetSetData(key string) (data []string, err error)

GetSetData

func (*RDSCommon) GetString

func (m *RDSCommon) GetString(key string) (v string, err error)

GetString 取 string

func (*RDSCommon) GetTTL

func (m *RDSCommon) GetTTL(key string) (ttl int64, err error)

GetTTL GetTTL

func (*RDSCommon) GetZSetCount added in v0.1.0

func (m *RDSCommon) GetZSetCount(key string) (count int64, err error)

GetZSetCount 获取指定区间min-max之间成员的数量

func (*RDSCommon) GetZSetCountByArea added in v0.1.0

func (m *RDSCommon) GetZSetCountByArea(key string, min, max int64) (count int64, err error)

GetZSetCountByArea 获取指定区间min-max 之间成员的数量

func (*RDSCommon) GetZSetWithScore added in v0.1.0

func (m *RDSCommon) GetZSetWithScore(key string, offset, limit int) (values []interface{}, err error)

getZSetWithScore

func (*RDSCommon) GetZSetWithScoreToInt64s added in v0.1.0

func (m *RDSCommon) GetZSetWithScoreToInt64s(key string, offset, limit int) (ii []int64, err error)

GetZSetWithScoreToInt64s ZSET to []int64

func (*RDSCommon) GetZSetWithScoreToInts added in v0.1.0

func (m *RDSCommon) GetZSetWithScoreToInts(key string, offset, limit int) (ii []int, err error)

GetZSetWithScoreToInts ZSET to []int

func (*RDSCommon) GetZSetWithScoreToStrings added in v0.1.0

func (m *RDSCommon) GetZSetWithScoreToStrings(key string, offset, limit int) (ss []string, err error)

GetZSetWithScoreToString ZSET to []string

func (*RDSCommon) HashFieldExists

func (m *RDSCommon) HashFieldExists(key, field string) (bool, error)

HashFieldExists hash某个field是否存在

func (*RDSCommon) Incr added in v0.1.9

func (m *RDSCommon) Incr(key string) (num int64, err error)

Incr 自增

func (*RDSCommon) Limit added in v0.6.8

func (m *RDSCommon) Limit(key string, seconds, timestamp int64) (num int64, err error)

func (*RDSCommon) Pool added in v0.3.8

func (m *RDSCommon) Pool(p *redis.Pool)

Pool

func (*RDSCommon) ReName

func (m *RDSCommon) ReName(dist, newKey string) (err error)

ReName rename key:dist to newkey

func (*RDSCommon) SETNX added in v0.1.0

func (m *RDSCommon) SETNX(key string, v interface{}) (bool, error)

SETNX key不存时,设置key的值为v

func (*RDSCommon) SetBit

func (m *RDSCommon) SetBit(key string, offset int64, v int) (err error)

SetBit

func (*RDSCommon) SetEX added in v0.1.0

func (m *RDSCommon) SetEX(key string, v interface{}, ex int64) (ok bool, err error)

SetEx 写入string,同时设置过期时间

SetEx(key,"value",24*time.Hour)

func (*RDSCommon) SetEXPIRE

func (m *RDSCommon) SetEXPIRE(key string, seconds int64) (bool, error)

SetEXPIRE 设置过期时间

func (*RDSCommon) SetEXPIREAT

func (m *RDSCommon) SetEXPIREAT(key string, timestamp int64) (bool, error)

SetEXPIREAT 设置过期时间(以时间戳的方式)

func (*RDSCommon) SetHash

func (m *RDSCommon) SetHash(key string, v interface{}) (err error)

SetHash设置 hash值

func (*RDSCommon) SetHashField

func (m *RDSCommon) SetHashField(key string, field, v interface{}) (int64, error)

SetHashField 设置某个field值

func (*RDSCommon) SetList added in v0.1.9

func (m *RDSCommon) SetList(key string, values []string) error

SetList 添加list

func (*RDSCommon) SetString

func (m *RDSCommon) SetString(key string, v interface{}) (ok bool, err error)

SetString 设置key的值为v

func (*RDSCommon) SetZSet added in v0.1.0

func (m *RDSCommon) SetZSet(key string, mp map[float64]interface{}) (err error)

SetZSet 添加一个新的ZSet

type RDSConfig

type RDSConfig struct {
	Host      string
	Port      int
	Password  string
	MaxIdle   int
	MaxActive int
	DB        int
}

RDSConfig redis 配置结构

Jump to

Keyboard shortcuts

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