login_qrcode.go 1009 字节
package cache

import (
	"encoding/json"
	"time"

	"gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
)

//二维码信息缓存
type LoginQrcodeCache struct {
}

func (lq LoginQrcodeCache) keyString(str string) string {
	str1 := KEY_PREFIX + "login:qrcode:" + str
	return str1
}

func (lq LoginQrcodeCache) Save(qrcode domain.QrcodeMessage) error {
	var exp = domain.QrcodeCodeExpire
	key := lq.keyString(qrcode.Id)
	bt, _ := json.Marshal(qrcode)
	result := clientRedis.Set(key, string(bt), time.Duration(exp)*time.Second)
	return result.Err()
}

func (lq LoginQrcodeCache) Remove(id string) error {
	keyStr := lq.keyString(id)
	result := clientRedis.Del(keyStr)
	return result.Err()
}

func (lq LoginQrcodeCache) Get(id string) (*domain.QrcodeMessage, error) {
	keyStr := lq.keyString(id)
	result := clientRedis.Get(keyStr)
	re, _ := result.Result()
	var data domain.QrcodeMessage
	err := json.Unmarshal([]byte(re), &data)
	if err != nil {
		return nil, err
	}
	return &data, err
}