cache

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: MIT Imports: 4 Imported by: 0

README

Cache

Cache This package basically provides us with an interface to communicate with Redis and thus manage the cache without using repetitive logic. That way, the logic is abstracted and we only focus on the functionality.

Go

This package makes use of the external package redis and our logger package.

Getting Started

Go is required in version 1.21 or higher.

Install

go get -u gitlab.com/prettytechnical-tools/cache

Features
  • Lightweight, less than 200 lines of code.
  • Easy to use.
Basic use
package main

import (
	"fmt"
	"log"

	"gitlab.com/prettytechnical-tools/cache"
)

func main() {
	var (
		redisHost = "localhost:6379"
		redisPassword = ""
	)
	c := cache.NewRedisClient(redisHost, redisPassword)
	value, err := c.Get("key")
	if err != nil {
		//manage the error
		log.Fatal(err)
	}
	
	//do something with the value
	fmt.Println(string(value))
}



Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(key string) ([]byte, error)
	Set(key string, value any, expiration time.Duration) error
	Drop(key string) error
	Incr(key string) error
	Exists(key string) (bool, error)
	Subscribe(channel string) <-chan *redis.Message
	Publish(channel string, msg []byte) error
	Ping() error
}

Cache is an in-memory storage to cache data.

func NewRedisClient

func NewRedisClient(address, password string) Cache

NewRedisClient returns a new redis client.

Jump to

Keyboard shortcuts

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