123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- package dao
- import (
- "context"
- "go-common/app/admin/ep/saga/model"
- "go-common/library/cache/memcache"
- "github.com/pkg/errors"
- )
- func (d *Dao) pingMC(c context.Context) (err error) {
- conn := d.mc.Get(c)
- defer conn.Close()
- if err = conn.Set(&memcache.Item{Key: "ping", Value: []byte{1}, Expiration: 0}); err != nil {
- err = errors.Wrap(err, "conn.Store(set,ping,1)")
- }
- return
- }
- // SetData set data info to memcache
- func (d *Dao) SetData(c context.Context, key string, dataMap map[string]*model.TeamDataResp) (err error) {
- var (
- conn = d.mc.Get(c)
- item *memcache.Item
- //dataMap = make(map[string]*model.TeamDataResp)
- )
- defer conn.Close()
- item = &memcache.Item{Key: key, Object: dataMap, Expiration: 0, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- err = errors.Wrapf(err, "conn.Set(%s,%v)", key, dataMap)
- return
- }
- return
- }
- // GetData get data info from memcache
- func (d *Dao) GetData(c context.Context, key string, dataMap *map[string]*model.TeamDataResp) (err error) {
- var (
- conn = d.mc.Get(c)
- reply *memcache.Item
- )
- defer conn.Close()
- reply, err = conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- return
- }
- err = errors.Wrapf(err, "conn.Get(%s)", key)
- return
- }
- if err = conn.Scan(reply, dataMap); err != nil {
- err = errors.Wrapf(err, "reply.Scan(%s)", string(reply.Value))
- return
- }
- return
- }
- // DeleteData delete data info in memcache
- func (d *Dao) DeleteData(c context.Context, key string) (err error) {
- var (
- conn = d.mc.Get(c)
- )
- defer conn.Close()
- err = conn.Delete(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- err = nil
- return
- }
- err = errors.Wrapf(err, "conn.Delete(%s)", key)
- }
- return
- }
- // SetPipeline set pipeline info info to memcache
- func (d *Dao) SetPipeline(c context.Context, key string, pipeline *model.PipelineDataResp) (err error) {
- var (
- conn = d.mc.Get(c)
- item *memcache.Item
- )
- defer conn.Close()
- item = &memcache.Item{Key: key, Object: pipeline, Expiration: 0, Flags: memcache.FlagJSON}
- if err = conn.Set(item); err != nil {
- err = errors.Wrapf(err, "conn.Set(%s,%v)", key, pipeline)
- return
- }
- return
- }
- // GetPipeline get pipeline info from memcache
- func (d *Dao) GetPipeline(c context.Context, key string) (pipeline *model.PipelineDataResp, err error) {
- var (
- conn = d.mc.Get(c)
- reply *memcache.Item
- )
- defer conn.Close()
- reply, err = conn.Get(key)
- if err != nil {
- if err == memcache.ErrNotFound {
- return
- }
- err = errors.Wrapf(err, "conn.Get(%s,%v)", key, pipeline)
- return
- }
- pipeline = new(model.PipelineDataResp)
- if err = conn.Scan(reply, pipeline); err != nil {
- err = errors.Wrapf(err, "reply.Scan(%s)", string(reply.Value))
- }
- return
- }
|