github.com/qichengzx/mattermost-server@v4.5.1-0.20180604164826-2c75247c97d0+incompatible/store/redis_supplier_reactions.go (about) 1 // Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved. 2 // See License.txt for license information. 3 4 package store 5 6 import ( 7 "context" 8 9 "github.com/mattermost/mattermost-server/mlog" 10 "github.com/mattermost/mattermost-server/model" 11 ) 12 13 func (s *RedisSupplier) ReactionSave(ctx context.Context, reaction *model.Reaction, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 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) *LayeredStoreSupplierResult { 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) *LayeredStoreSupplierResult { 28 var resultdata []*model.Reaction 29 found, err := s.load("reactions:"+postId, &resultdata) 30 if found { 31 result := NewSupplierResult() 32 result.Data = resultdata 33 return result 34 } 35 if err != nil { 36 mlog.Error("Redis encountered an error on read: " + err.Error()) 37 } 38 39 result := s.Next().ReactionGetForPost(ctx, postId, hints...) 40 41 if err := s.save("reactions:"+postId, result.Data, REDIS_EXPIRY_TIME); err != nil { 42 mlog.Error("Redis encountered and error on write: " + err.Error()) 43 } 44 45 return result 46 } 47 48 func (s *RedisSupplier) ReactionDeleteAllWithEmojiName(ctx context.Context, emojiName string, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 49 // Ignoring this. It's probably OK to have the emoji slowly expire from Redis. 50 return s.Next().ReactionDeleteAllWithEmojiName(ctx, emojiName, hints...) 51 } 52 53 func (s *RedisSupplier) ReactionPermanentDeleteBatch(ctx context.Context, endTime int64, limit int64, hints ...LayeredStoreHint) *LayeredStoreSupplierResult { 54 // Ignoring this. It's probably OK to have the emoji slowly expire from Redis. 55 return s.Next().ReactionPermanentDeleteBatch(ctx, endTime, limit, hints...) 56 }