github.com/xzl8028/xenia-server@v0.0.0-20190809101854-18450a97da63/store/redis_supplier_reactions.go (about)

     1  // Copyright (c) 2016-present Xenia, Inc. All Rights Reserved.
     2  // See License.txt for license information.
     3  
     4  package store
     5  
     6  import (
     7  	"context"
     8  
     9  	"github.com/xzl8028/xenia-server/mlog"
    10  	"github.com/xzl8028/xenia-server/model"
    11  )
    12  
    13  func (s *RedisSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) (*model.Reaction, *model.AppError) {
    14  	if err := s.client.Del("reactions:" + reaction.PostId).Err(); err != nil {
    15  		mlog.Error("Redis failed to remove key reactions:" + reaction.PostId + " Error: " + err.Error())
    16  	}
    17  	return s.Next().ReactionSave(ctx, reaction, hints...)
    18  }
    19  
    20  func (s *RedisSupplier) ReactionDelete(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) (*model.Reaction, *model.AppError) {
    21  	if err := s.client.Del("reactions:" + reaction.PostId).Err(); err != nil {
    22  		mlog.Error("Redis failed to remove key reactions:" + reaction.PostId + " Error: " + err.Error())
    23  	}
    24  	return s.Next().ReactionDelete(ctx, reaction, hints...)
    25  }
    26  
    27  func (s *RedisSupplier) ReactionGetForPost(ctx context.Context, postId string, hints ...LayeredStoreHint) ([]*model.Reaction, *model.AppError) {
    28  	var reaction []*model.Reaction
    29  	found, err := s.load("reactions:"+postId, &reaction)
    30  	if found {
    31  		return reaction, nil
    32  	}
    33  
    34  	if err != nil {
    35  		mlog.Error("Redis encountered an error on read: " + err.Error())
    36  	}
    37  
    38  	reaction, appErr := s.Next().ReactionGetForPost(ctx, postId, hints...)
    39  	if appErr != nil {
    40  		return nil, appErr
    41  	}
    42  
    43  	if err := s.save("reactions:"+postId, reaction, REDIS_EXPIRY_TIME); err != nil {
    44  		mlog.Error("Redis encountered and error on write: " + err.Error())
    45  	}
    46  
    47  	return reaction, nil
    48  }
    49  
    50  func (s *RedisSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *model.AppError {
    51  	// Ignoring this. It's probably OK to have the emoji slowly expire from Redis.
    52  	return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...)
    53  }
    54  
    55  func (s *RedisSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) (int64, *model.AppError) {
    56  	// Ignoring this. It's probably OK to have the emoji slowly expire from Redis.
    57  	return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit, hints...)
    58  }
    59  
    60  func (s *RedisSupplier) ReactionsBulkGetForPosts(ctx context.Context, postIds []string, hints ...LayeredStoreHint) ([]*model.Reaction, *model.AppError) {
    61  	// Ignoring this.
    62  	return s.Next().ReactionsBulkGetForPosts(ctx, postIds, hints...)
    63  }