redis

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2020 License: Apache-2.0 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

Overview

使用方法:

1. init

func init(){
	InitRds(&RDSConfig{
		Host:"127.0.0.1",
		Port:2379,
		Password:"123456",
		MaxIdle:10,
		MaxActive:10000,
		DB:0,
	})
}

2.调用操作方法 rc:=new(RdsCommon) val,err:=rc.Get(key) .... ...

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

func (*RDSCommon) DEL

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

DEL 删除某个Key

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)

================bit======================

func (*RDSCommon) GetHashAll

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

GetHash get hash all to obj

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

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

GetInt64 取 int64

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)

==============key操作======================== GetTTL GetTTL

func (*RDSCommon) HashFieldExists

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

HashFieldExists hash某个field是否存在

func (*RDSCommon) ReName

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

ReName rename key:dist to newkey

func (*RDSCommon) SetBit

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

SetBit

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

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

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

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

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

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

S etString 设置值

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