gocache

package module
v0.0.0-...-84f7d08 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 6 Imported by: 0

README

Gocache

This library is a shared package for standardized cache implementation.

What is cache?

A cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for that data are served up faster than is possible by accessing the data's primary storage location.

Installation

You can run this in your terminal

go get -u github.com/runsystemid/gocache

Import this library in your main function or bootstrap function.

import "github.com/runsystemid/gocache"

Contributing

Contributions are welcome! Please follow the Contribution Guidelines.

License

This project is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNil .
	ErrNil = errors.New("cache: value doesnt exists")
	// ErrCache .
	ErrCache = errors.New("cache error")
)

Functions

This section is empty.

Types

type Redis

type Redis struct {
	Client *redis.Client
}

func New

func New(conf RedisConfig) *Redis

New redis

func (*Redis) Close

func (c *Redis) Close() error

Close .

func (*Redis) Decrement

func (c *Redis) Decrement(ctx context.Context, key string, value int64) (int64, error)

Decrease value for the given key

func (*Redis) Delete

func (c *Redis) Delete(ctx context.Context, keys ...string) (int64, error)

Delete data based on key

func (*Redis) Exists

func (c *Redis) Exists(ctx context.Context, keys ...string) (bool, error)

Check if key exist in Redis

func (*Redis) Expire

func (c *Redis) Expire(ctx context.Context, key string, expiration time.Duration) error

Set expiration for the given key

func (*Redis) Get

func (c *Redis) Get(ctx context.Context, key string, value interface{}) error

Get data for the given key

func (*Redis) HGetAll

func (c *Redis) HGetAll(ctx context.Context, key string) (map[string]string, error)

func (*Redis) HSet

func (c *Redis) HSet(ctx context.Context, key string, value map[string]interface{}) error

func (*Redis) Increment

func (c *Redis) Increment(ctx context.Context, key string, value int64) (int64, error)

Increase value for the given key

func (*Redis) Keys

func (c *Redis) Keys(ctx context.Context, pattern string) ([]string, error)

Get available key for the given pattern

func (*Redis) Ping

func (c *Redis) Ping(ctx context.Context) error

Ping .

func (*Redis) Put

func (c *Redis) Put(ctx context.Context, key string, value interface{}, expiration time.Duration) error

Put data to redis based on key

func (*Redis) TTL

func (c *Redis) TTL(ctx context.Context, key string) (time.Duration, error)

Check expiration for the given key

type RedisConfig

type RedisConfig struct {
	Mode     string
	Address  string
	Port     int
	Password string
}

type Service

type Service interface {
	Get(ctx context.Context, key string, value interface{}) error
	Put(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	HGetAll(ctx context.Context, key string) (map[string]string, error)
	HSet(ctx context.Context, key string, value map[string]interface{}) error
	Expire(ctx context.Context, key string, expiration time.Duration) error
	Delete(ctx context.Context, keys ...string) (int64, error)
	Exists(ctx context.Context, keys ...string) (bool, error)
	Increment(ctx context.Context, key string, value int64) (int64, error)
	Decrement(ctx context.Context, key string, value int64) (int64, error)
	Keys(ctx context.Context, pattern string) ([]string, error)
	TTL(ctx context.Context, key string) (time.Duration, error)
	Ping(ctx context.Context) error
	Close() error
}

Directories

Path Synopsis
Code generated by MockGen.
Code generated by MockGen.

Jump to

Keyboard shortcuts

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