provider에도 Query func 추가
This commit is contained in:
@ -21,8 +21,8 @@ func make_cache_stage[T any]() *cache_stage[T] {
|
||||
}
|
||||
|
||||
type Consumer interface {
|
||||
Query(key string) *Authorization
|
||||
Touch(key string) bool
|
||||
Query(string) *Authorization
|
||||
Touch(string) bool
|
||||
}
|
||||
|
||||
type consumer_common[T any] struct {
|
||||
|
||||
@ -11,8 +11,9 @@ import (
|
||||
)
|
||||
|
||||
type Provider interface {
|
||||
Update(key string, input *Authorization) error
|
||||
Delete(key string) error
|
||||
Update(string, *Authorization) error
|
||||
Delete(string) error
|
||||
Query(string) (*Authorization, error)
|
||||
}
|
||||
|
||||
type provider_redis struct {
|
||||
@ -91,6 +92,22 @@ func (p *provider_redis) Delete(key string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *provider_redis) Query(key string) (*Authorization, error) {
|
||||
payload, err := p.redisClient.Get(p.ctx, key).Result()
|
||||
if err == redis.Nil {
|
||||
return nil, nil
|
||||
} else if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var auth Authorization
|
||||
if err := bson.Unmarshal([]byte(payload), &auth); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &auth, nil
|
||||
}
|
||||
|
||||
func (p *provider_mongo) Update(key string, input *Authorization) error {
|
||||
_, _, err := p.mongoClient.Update(session_collection_name, bson.M{
|
||||
"key": key,
|
||||
@ -110,3 +127,12 @@ func (p *provider_mongo) Delete(key string) error {
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *provider_mongo) Query(key string) (*Authorization, error) {
|
||||
var auth Authorization
|
||||
err := p.mongoClient.FindOneAs(session_collection_name, bson.M{
|
||||
"key": key,
|
||||
}, &auth)
|
||||
|
||||
return &auth, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user