세션 provider, consumer 인터페이스 변경
This commit is contained in:
@ -81,7 +81,7 @@ func (p *provider_redis) New(input *Authorization) (string, error) {
|
||||
return string(pk), err
|
||||
}
|
||||
|
||||
func (p *provider_redis) Invalidate(account primitive.ObjectID) error {
|
||||
func (p *provider_redis) RevokeAll(account primitive.ObjectID) error {
|
||||
prefix := account.Hex()
|
||||
sks, err := p.redisClient.Keys(p.ctx, prefix+"*").Result()
|
||||
if err != nil {
|
||||
@ -130,7 +130,8 @@ func (p *provider_redis) Touch(pk string) (bool, error) {
|
||||
|
||||
type consumer_redis struct {
|
||||
consumer_common[*sessionRedis]
|
||||
redisClient *redis.Client
|
||||
redisClient *redis.Client
|
||||
deleteChannel string
|
||||
}
|
||||
|
||||
func newConsumerWithRedis(ctx context.Context, redisUrl string, ttl time.Duration) (Consumer, error) {
|
||||
@ -139,6 +140,9 @@ func newConsumerWithRedis(ctx context.Context, redisUrl string, ttl time.Duratio
|
||||
return nil, err
|
||||
}
|
||||
|
||||
deleteChannel := fmt.Sprintf("%s_%d_d", communication_channel_name_prefix, redisClient.Options().DB)
|
||||
sub := redisClient.Subscribe(ctx, deleteChannel)
|
||||
|
||||
consumer := &consumer_redis{
|
||||
consumer_common: consumer_common[*sessionRedis]{
|
||||
ttl: ttl,
|
||||
@ -146,12 +150,10 @@ func newConsumerWithRedis(ctx context.Context, redisUrl string, ttl time.Duratio
|
||||
stages: [2]*cache_stage[*sessionRedis]{make_cache_stage[*sessionRedis](), make_cache_stage[*sessionRedis]()},
|
||||
startTime: time.Now(),
|
||||
},
|
||||
redisClient: redisClient,
|
||||
redisClient: redisClient,
|
||||
deleteChannel: deleteChannel,
|
||||
}
|
||||
|
||||
deleteChannel := fmt.Sprintf("%s_%d_d", communication_channel_name_prefix, redisClient.Options().DB)
|
||||
sub := redisClient.Subscribe(ctx, deleteChannel)
|
||||
|
||||
go func() {
|
||||
stageswitch := time.Now().Add(ttl)
|
||||
tickTimer := time.After(ttl)
|
||||
@ -317,7 +319,14 @@ func (c *consumer_redis) Touch(pk string) (Authorization, error) {
|
||||
return Authorization{}, nil
|
||||
}
|
||||
|
||||
func (c *consumer_redis) IsInvalidated(accid primitive.ObjectID) bool {
|
||||
func (c *consumer_redis) Revoke(pk string) {
|
||||
sk := publickey_to_storagekey(publickey(pk))
|
||||
|
||||
c.redisClient.Del(c.ctx, string(sk))
|
||||
c.redisClient.Publish(c.ctx, c.deleteChannel, string(sk)).Result()
|
||||
}
|
||||
|
||||
func (c *consumer_redis) IsRevoked(accid primitive.ObjectID) bool {
|
||||
sk := make_storagekey(accid)
|
||||
|
||||
c.lock.Lock()
|
||||
|
||||
Reference in New Issue
Block a user