gomemcacheex povides wrapper for Go memcached client (bradfitz/gomemcache) that name ClientWrapper
.
ClientWrapper
can register callback functions for each methods(Get
, Set
, Delete
, etc) similar to GORM.
go get github.com/matsuby/gomemcacheex
package main
import (
"fmt"
"github.com/bradfitz/gomemcache/memcache"
"github.com/matsuby/gomemcacheex/memcacheex"
)
func main() {
// create wrapper for memcached client
cw := memcacheex.NewClientWrapper(memcache.New("localhost:11211"))
// register callback functions
cw.Callback().Set().Before().Register("gomemcacheex:set-before", func(args, results []any) {
fmt.Println("--- Set: Before")
fmt.Println(args...)
})
cw.Callback().Get().After().Register("gomemcacheex:get-after", func(args, results []any) {
fmt.Println("--- Get: After")
fmt.Println(args...)
fmt.Println(results...)
})
// call methods, then invoke registered callback functions
_ = cw.Set(&memcache.Item{Key: "test_key", Value: []byte("test_value")})
_, _ = cw.Get("test_key")
}
gomemcacheex provodes interface and mock for memcached client. These may help you with your unit tests.