session provider에도 touch 추가
This commit is contained in:
@ -31,6 +31,7 @@ type Provider interface {
|
||||
New(*Authorization) (string, error)
|
||||
Delete(primitive.ObjectID) error
|
||||
Query(string) (*Authorization, error)
|
||||
Touch(string) (bool, error)
|
||||
}
|
||||
|
||||
type Consumer interface {
|
||||
|
||||
@ -77,6 +77,24 @@ func (p *provider_mongo) Query(pk string) (*Authorization, error) {
|
||||
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 {
|
||||
consumer_common[*sessionMongo]
|
||||
ids map[primitive.ObjectID]storagekey
|
||||
|
||||
@ -87,6 +87,20 @@ func (p *provider_redis) Query(pk string) (*Authorization, error) {
|
||||
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 {
|
||||
consumer_common[*sessionRedis]
|
||||
redisClient *redis.Client
|
||||
|
||||
Reference in New Issue
Block a user