feat(dao): change string to proto.KeyBase

This commit is contained in:
HuangJiaLuo 2021-10-06 20:39:20 +08:00
parent d4d93a0e51
commit f17cab2016
1 changed files with 9 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package dao
import (
"gitee.com/timedb/wheatCache/pkg/errorx"
"gitee.com/timedb/wheatCache/pkg/lru"
"gitee.com/timedb/wheatCache/pkg/proto"
"gitee.com/timedb/wheatCache/pkg/structure"
"gitee.com/timedb/wheatCache/pkg/structure/stringx"
)
@ -17,7 +18,7 @@ func NewDao(lru lru.CacheInterface) *Dao {
}
}
func (d *Dao) Set(key string, strVal string) (string, error) {
func (d *Dao) Set(key *proto.BaseKey, strVal string) (string, error) {
value, ok := d.lru.Get(key)
if ok {
if val, ok := value.(structure.StringXInterface); ok {
@ -37,10 +38,10 @@ func (d *Dao) Set(key string, strVal string) (string, error) {
return result, nil
}
func (d *Dao) Get(key string) (string, error) {
func (d *Dao) Get(key *proto.BaseKey) (string, error) {
val, ok := d.lru.Get(key)
if !ok {
return "", errorx.NotKeyErr(key)
return "", errorx.NotKeyErr(key.Key)
}
strVal, ok := val.(structure.StringXInterface)
@ -51,7 +52,7 @@ func (d *Dao) Get(key string) (string, error) {
return strVal.Get(), nil
}
func (d *Dao) Add(key string, renewal int32) (string, error) {
func (d *Dao) Add(key *proto.BaseKey, renewal int32) (string, error) {
value, lruOk := d.lru.Get(key)
if !lruOk {
val := stringx.NewStringSingle()
@ -75,7 +76,7 @@ func (d *Dao) Add(key string, renewal int32) (string, error) {
return res, nil
}
func (d *Dao) Reduce(key string, renewal int32) (string, error) {
func (d *Dao) Reduce(key *proto.BaseKey, renewal int32) (string, error) {
value, lruOk := d.lru.Get(key)
if !lruOk {
val := stringx.NewStringSingle()
@ -99,7 +100,7 @@ func (d *Dao) Reduce(key string, renewal int32) (string, error) {
return res, nil
}
func (d *Dao) Setbit(key string, val bool, offer int32) error {
func (d *Dao) Setbit(key *proto.BaseKey, val bool, offer int32) error {
value, lruOk := d.lru.Get(key)
if !lruOk {
valStr := stringx.NewStringSingle()
@ -119,10 +120,10 @@ func (d *Dao) Setbit(key string, val bool, offer int32) error {
return nil
}
func (d *Dao) GetBit(key string, offer int32) (bool, error) {
func (d *Dao) GetBit(key *proto.BaseKey, offer int32) (bool, error) {
value, lruOk := d.lru.Get(key)
if !lruOk {
return false, errorx.NotKeyErr(key)
return false, errorx.NotKeyErr(key.Key)
}
strVal, ok := value.(structure.StringXInterface)
if !ok {