redis-util business-friendly encapsulation of redis operations, such as the common cache set get operation

redis-util

方便业务使用的redis操作封装,比如常见的缓存set get操作, 一行代码搞定,不像开源库需要写好多行

使用方法

package main

import (
	"fmt"

	redisutil "github.com/cclehui/redis-util"
	"github.com/gomodule/redigo/redis"
)

func main() {
	server := "xxxxx:6379"
	password := "wxxxxxxxxx"

	redisClient := &redis.Pool{
		Dial: func() (redis.Conn, error) {
			c, err := redis.Dial("tcp", server)
			if err != nil {
				return nil, err
			}

			if _, err := c.Do("AUTH", password); err != nil {
				c.Close()
				return nil, err
			}

			return c, nil
		},
	}

	redisUtil := redisutil.NewRedisUtil(redisClient)
	cacheKey := "cclehui_test_set_get_key_211022"

	_ = redisUtil.Set(cacheKey, "axxxaa", 3600) // 设置缓存

	valueStrRes := ""
	_, _ = redisUtil.Get(cacheKey, &valueStrRes) // 获取缓存
	fmt.Println("获取缓存:", valueStrRes)

	_ = redisUtil.Del(cacheKey) // Del

	value, _ := redisUtil.Incr(cacheKey)
	fmt.Println("Incr:", value)

	value, _ = redisUtil.Decr(cacheKey)
	fmt.Println("Decr:", value)
}

Similar Resources

sigurls is a reconnaissance tool, it fetches URLs from AlienVault's OTX, Common Crawl, URLScan, Github and the Wayback Machine.

sigurls is a reconnaissance tool, it fetches URLs from AlienVault's OTX, Common Crawl, URLScan, Github and the Wayback Machine. DiSCLAIMER: fe

May 22, 2021

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

a decision & trigger framework backed by Google's Common Expression Language used in graphikDB

Nov 15, 2022

Use Golang to implement PHP's common built-in functions.

PHP2Go Use Golang to implement PHP's common built-in functions. About 140+ functions have been implemented. Install go get github.com/syyongx/php2go R

Dec 28, 2022

The one-stop shop for most common Go functions

The one-stop shop for most common Go functions

Pandati The one stop shop for most common Go functions Table of contents Pandati The one stop shop for most common Go functions Table of contents Purp

Mar 21, 2022

common tools for golang

utils common tools for golang package main

Dec 27, 2021

Common utils that need in every development

Utils modules Common utils that need in every development Modules Conversion String IntToString(num int) string Int8ToString(num int8) string Int16ToS

Nov 5, 2021

With Pasteback you can store common terms and paste them back to clipboard

Pasteback With Pasteback you can store common terms and paste them back to clipboard when needed. There is one central spot to put every string into y

Nov 22, 2021

Helper functions for common scenarios, using Go generics.

zeroflucs generics When writing Go code for Go 1.17 or below, we've all written more than our fair share of methods to check "does this slice contain

Feb 18, 2022

Yet another StructTag, with some features liked cache and alias.

Yet another StructTag, with some features liked cache and alias.

Nov 1, 2021
Related tags
subtraction operations and also parentheses to indicate order of operations

basic parsing expose a Calculate method that accepts a string of addition / subtraction operations and also parentheses to indicate order of operation

Feb 22, 2022
A simple business indicator tool that uses a sliding window to detect whether the indicator exceeds the threshold

melon A simple business indicator tool that uses a sliding window to detect whether the indicator exceeds the threshold Usage //create the metric //th

Jul 11, 2021
An application written in Go to generate fractals like the Mandelbrot set and the Julia set.
An application written in Go to generate fractals like the Mandelbrot set and the Julia set.

Fractals An application written in Go to generate fractals like the Mandelbrot set and the Julia set. Screenshots Mandelbrot set Julia set Prerequisit

May 9, 2022
A comprehensive, efficient, and reusable util function library of go.

Lancet Lancet is a comprehensive, efficient, and reusable util function library of go. Inspired by the java apache common package and lodash.js. Engli

Jan 8, 2023
Simple utility to get/set the PWM duty cycle and to measure the RPM for a fan connected to the 4-pin header on the CM4IO.

cm4iofan Simple utility to get/set the PWM duty cycle and to measure the RPM for a fan connected to the 4-pin header on the CM4IO. Requirements Enable

Mar 31, 2022
gopkg is a universal utility collection for Go, it complements offerings such as Boost, Better std, Cloud tools.

gopkg is a universal utility collection for Go, it complements offerings such as Boost, Better std, Cloud tools. Table of Contents Introduction

Jan 5, 2023
Minimalistic library for basic matrix operations.

MATRIX Maybe a bit slow, but minimalistic library for basic matrix operations. Available functions Function signature Description Equal(a, b [][]float

Nov 4, 2021
A go1.18+ package to (maybe) simplify performing operations on slices in a fluent-like style.

sop ✨ W.I.P. ✨ sop (slices operation) is a go1.18+ package to (maybe) simplify performing operations on slices in a fluent-like style with common oper

Oct 1, 2022
Deduplicated and GC-friendly string store

This library helps to store big number of strings in structure with small number of pointers to make it friendly to Go garbage collector.

Nov 10, 2021
A library that provides Go Generics friendly "optional" features.

go-optional A library that provides Go Generics friendly "optional" features. Synopsis some := optional.Some[int](123) fmt.Printf("%v\n", some.IsSome(

Dec 20, 2022