zdpgo_redis

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2022 License: MIT Imports: 9 Imported by: 0

README

zdpgo_redis

使用Golang操作Redis的快捷工具库

功能列表:

  • 基于redis的分布式锁

版本历史

  • v0.1.1 2022/04/16 新增:string类型的crud操作
  • v0.1.2 2022/07/16 优化:代码结构优化

使用示例

string类型的增删改查
package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_redis"
)

func main() {
	r := zdpgo_redis.New(zdpgo_redis.Config{
		Host:     "localhost",
		Port:     6379,
		Database: 0,
	})

	// 增加
	r.String.Add("a", 1)
	r.String.AddMany("b", 1.1, "c", true, "d", "abc")

	// 查询
	aValue, err := r.String.Find("a")
	if err != nil {
		return
	}
	fmt.Println(aValue)

	manyValues, err := r.String.FindMany("b", "c", "d")
	if err != nil {
		return
	}
	fmt.Println(manyValues)

	// 修改
	r.String.Update("a", 1)
	r.String.UpdateMany("b", 1.1, "c", true, "d", "abc")

	keys, err := r.Common.Keys()
	if err != nil {
		return
	}
	fmt.Println("删除之前:", keys)

	// 删除
	r.String.Delete("a")
	r.String.DeleteMany("b", "c", "d")

	keys, err = r.Common.Keys()
	if err != nil {
		return
	}
	fmt.Println("删除之后:", keys)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v0.1.1

type Config struct {
	Host      string `yaml:"host" json:"host"`             // 主机地址
	Port      int    `yaml:"port" json:"port"`             // 端口号
	Database  int    `yaml:"database" json:"database"`     // 数据库
	Username  string `yaml:"username" json:"username"`     // 用户名
	Password  string `yaml:"password" json:"password"`     // 密码
	PoolSize  int    `yaml:"pool_size" json:"pool_size"`   // 连接池连接数
	StreamTag string `yaml:"stream_tag" json:"stream_tag"` // 流标签
}

Config redis配置对象

type Redis

type Redis struct {
	Common *common.Common  // Redis通用操作对象
	String *rstring.String // 操作字符串的核心对象
	List   *rlist.List     // 操作列表的核心对象
	Hash   *rhash.Hash     // 操作hash的核心对象
	Set    *rset.Set       // 操作set的核心对象
	// contains filtered or unexported fields
}

Redis 操作redis的核心对象

func New

func New(config Config) *Redis

New 创建Redis操作对象

func (*Redis) Status

func (r *Redis) Status() bool

Status 查看Redis服务状态

Directories

Path Synopsis
Package errwrap implements methods to formalize error wrapping in Go.
Package errwrap implements methods to formalize error wrapping in Go.
examples
Package redis implements a Redis client.
Package redis implements a Redis client.
Package xxhash implements the 64-bit variant of xxHash (XXH64) as described at http://cyan4973.github.io/xxHash/.
Package xxhash implements the 64-bit variant of xxHash (XXH64) as described at http://cyan4973.github.io/xxHash/.

Jump to

Keyboard shortcuts

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