mredis

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2022 License: MulanPSL-2.0 Imports: 7 Imported by: 0

README

mredis

介绍

封装redis,主要是对goredis的简单封装

软件架构
  1. 依赖 github.com/go-redis/redis/v8
  2. 使用sync.Pool进行连接管理
安装教程
  1. go get -u gitee.com/masaichi/mredis
使用说明
  1. 创建mredis示例
redisService := NewMRedis()
  1. 设置连接参数
redisService.SetConn(viper.GetString("host"), viper.GetInt("port"), viper.GetString("password"), viper.GetInt("db"))
  1. 使用
        //设置缓存
        dataStr, _ := json.Marshal(data)
	redisService.SetCache("name123", string(dataStr))
        //获取缓存
        res := redisService.GetCache("name123")
        //加锁 时间默认30秒
        if redisService.Lock(lockKey) {
		log.Println("锁成功")
	}
        //解锁
        redisService.Unlock(lockKey)
        //删除缓存
        redisService.Del(key)
参与贡献
  1. Fork 本仓库
  2. 新建 Feat_xxx 分支
  3. 提交代码
  4. 新建 Pull Request
特技
  1. 使用 Readme_XXX.md 来支持不同的语言,例如 Readme_en.md, Readme_zh.md
  2. Gitee 官方博客 blog.gitee.com
  3. 你可以 https://gitee.com/explore 这个地址来了解 Gitee 上的优秀开源项目
  4. GVP 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目
  5. Gitee 官方提供的使用手册 https://gitee.com/help
  6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 https://gitee.com/gitee-stars/

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MRedis

type MRedis struct {
	mstruct.MCacheConfig
	LockExpire time.Duration
}

func NewMRedis

func NewMRedis() *MRedis

实例化一个操作对象

func (*MRedis) Del

func (this *MRedis) Del(key string)

删除缓存

func (*MRedis) GetCache

func (this *MRedis) GetCache(key string) interface{}

获取缓存

func (*MRedis) Lock

func (this *MRedis) Lock(key string) bool

func (*MRedis) SetCache

func (this *MRedis) SetCache(key string, val interface{})

设置缓存

func (*MRedis) SetConn

func (this *MRedis) SetConn(host string, port int, pwd string, db int)

设置连接

func (*MRedis) Unlock

func (this *MRedis) Unlock(key string)

解锁

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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