rimcu

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 6 Imported by: 0

README

rimcu - Redis server-assisted client side caching Go library

build workflow PkgGoDev codecov Maintainability

Rimcu is Go library for Redis server-assisted client side caching. In other words, it is a combination of Redis cient library and in memory cache library.

System Requirements

Redis 6 or newer, with it's client side caching feature

How it works

It caches the Redis data in your server's RAM and sync it to Redis server when the data changed. So you don't need to always ask the Redis server to get your cache data.

It supports three modes:

  • RESP2: single node Redis with RESP2 protocol, it is the default one
  • RESP2ClusterProxy: Redis cluster with RESP2 protocol and front proxy
  • RESP3: single node Redis with RESP3 protocol, not fully tested yet

Examples


Features

Features Status Description
Metrics Client ❌ 🔧 Configurable metrics client
Password Support ❌ 🔧
Strings ❌ 🔧 redis strings data type
list ❌ 🔧 redis list data type
hash ❌ 🔧 redis hash data type

Connection Pool

Features Status Description
Single Pool ❌ 🔧 Single conn pool for all cache types
Vanilla Redigo Pool ❌ 🔧 Reuse vanilla redigo pool
Max Number of Connections
Waiting for connection with timeout
Idle connection checking ❌ 🔧
Healthcheck ❌ 🔧

Caches

We categorize the cache based on the Redis data types mention in https://redis.io/docs/manual/data-types/. We need to do this because each type of cache will be stored differently.

StringsCache

StringsCache is cache for redis strings data type.

Implemented Commands
  • Setex
  • Get
  • Del
  • MSet (waiting support at RESP2)
  • MGet (waiting support at RESP2)
  • Append

ListCache (RESP2)

IT IS UNDER REWORK

Old implementation can be found at https://github.com/iwanbk/rimcu/blob/v0.01/resp2/listcache.go#L33

ListCache is cache for Redis list data type which uses RESP2 protocol. It is still in very early development phase. See the godoc page for more explanation.
 
Implemented commands:
- [x]LPOP
- [x]RPUSH
- [x]GET (it is Rimcu specific command)
- [ ]...

Development

Local Test

export TEST_REDIS_ADDRESS=127.0.0.1:6379 # replace with your redis 6 server
go test ./...

TODO

Features Status Description
Unify inmem cache ❌ 🔧 resp2 & resp3 currently using two different memcache lib

CREDITS

  • redigo redis package is copied and modified to this repo. It is used to provide RESP2 support.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// redis server address
	// in case of RESP2ClusterProxy protocol, it is the address of the proxy
	ServerAddr string

	// size of the  in memory cache
	// Default is 10K
	CacheSize int

	// Protocol of redis being used.
	//
	// The default is ProtoResp2
	Protocol Protocol

	// Logger to be used, the default logger will print nothing
	Logger logger.Logger

	// ClusterNodes is a list of cluster nodes
	// only being used by ProtoResp2ClusterProxy protocol.
	// We currently need to list all of the slave IPs
	// TODO: make it auto detect cluster nodes
	ClusterNodes []string
}

Config represents config of Cache

type Protocol

type Protocol string

Protocol represents the underlying Redis protocol used by rimcu. It currently support RESP2 & RESP3 (experimental)

const (
	// ProtoResp2 represent RESP2 protocol that is used from Redis 2
	ProtoResp2 Protocol = "RESP2"

	// ProtoResp2ClusterProxy represent RESP2 protocol on redis cluster
	// with front proxy
	ProtoResp2ClusterProxy Protocol = "RESP2ClusterProxy"

	// ProtoResp3 represents RESP3 protocol that supported since Redis 6
	ProtoResp3 Protocol = "RESP3"
)

type Rimcu

type Rimcu struct {
	// contains filtered or unexported fields
}

Rimcu is a redis client which implements client side caching. It is safe for concurrent use by multiples goroutine

func New

func New(cfg Config) *Rimcu

New creates a new Rimcu redis client

func (*Rimcu) NewStringsCache

func (r *Rimcu) NewStringsCache(cfg StringsCacheConfig) (*StringsCache, error)

NewStringsCache creates a new strings cache and do the required initialization

type StringsCache

type StringsCache struct {
	// contains filtered or unexported fields
}

StringsCache is Rimcu client for the strings redis data type

func (*StringsCache) Del

func (sc *StringsCache) Del(ctx context.Context, key string) error

Del deletes the key in both memory cache and redis server

func (*StringsCache) Get

func (sc *StringsCache) Get(ctx context.Context, key string, expSecond int) (result.StringsResult, error)

Get gets the value of key.

It gets from the redis server only if the value not exists in memory cache, it then put the value from server in the in memcache with the given expiration

func (*StringsCache) Setex

func (sc *StringsCache) Setex(ctx context.Context, key string, val interface{}, exp int) error

Setex sets the key to hold the string value with the given expiration second.

Calling this func will invalidate inmem cache of this key's slot in all nodes

type StringsCacheConfig

type StringsCacheConfig struct {
	CacheSize   int
	CacheTTLSec int
	// contains filtered or unexported fields
}

StringsCacheConfig is the configuration of the StringsCache

Directories

Path Synopsis
internal
redigo/redis
Package redis is a client for the Redis database.
Package redis is a client for the Redis database.

Jump to

Keyboard shortcuts

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