session provider에도 touch 추가

This commit is contained in:
2023-09-04 11:56:56 +09:00
parent d396a35713
commit 0eefb438a6
3 changed files with 33 additions and 0 deletions

View File

@ -31,6 +31,7 @@ type Provider interface {
New(*Authorization) (string, error) New(*Authorization) (string, error)
Delete(primitive.ObjectID) error Delete(primitive.ObjectID) error
Query(string) (*Authorization, error) Query(string) (*Authorization, error)
Touch(string) (bool, error)
} }
type Consumer interface { type Consumer interface {

View File

@ -77,6 +77,24 @@ func (p *provider_mongo) Query(pk string) (*Authorization, error) {
return &auth, err return &auth, err
} }
func (p *provider_mongo) Touch(pk string) (bool, error) {
sk := publickey_to_storagekey(publickey(pk))
worked, _, err := p.mongoClient.Update(session_collection_name, bson.M{
"key": sk,
}, bson.M{
"$currentDate": bson.M{
"_ts": bson.M{"$type": "date"},
},
}, options.Update().SetUpsert(false))
if err != nil {
logger.Println("provider Touch :", err)
return false, err
}
return worked, nil
}
type consumer_mongo struct { type consumer_mongo struct {
consumer_common[*sessionMongo] consumer_common[*sessionMongo]
ids map[primitive.ObjectID]storagekey ids map[primitive.ObjectID]storagekey

View File

@ -87,6 +87,20 @@ func (p *provider_redis) Query(pk string) (*Authorization, error) {
return &auth, nil return &auth, nil
} }
func (p *provider_redis) Touch(pk string) (bool, error) {
sk := publickey_to_storagekey(publickey(pk))
ok, err := p.redisClient.Expire(p.ctx, string(sk), p.ttl).Result()
if err == redis.Nil {
// 이미 만료됨
return false, nil
} else if err != nil {
logger.Println("consumer Touch :", err)
return false, err
}
return ok, nil
}
type consumer_redis struct { type consumer_redis struct {
consumer_common[*sessionRedis] consumer_common[*sessionRedis]
redisClient *redis.Client redisClient *redis.Client