redis.go 472 B

123456789101112131415161718192021222324
  1. package cache
  2. import (
  3. "context"
  4. "github.com/redis/go-redis/v9"
  5. "server/global"
  6. )
  7. var Redis *redis.Client
  8. func init() {
  9. Redis = global.GVA_REDIS
  10. }
  11. // 存储离线用户的消息
  12. func StoreMessages(id, msg string) error {
  13. return Redis.LPush(context.Background(), "offline:"+id, msg).Err()
  14. }
  15. // 获取用户的离线信息
  16. func GetStoreMessages(id string) []string {
  17. result, _ := Redis.LRange(context.Background(), "offline:"+id, 0, -1).Result()
  18. return result
  19. }