package com.red.circle.other.infra.database.cache.service.other.impl;

import com.fasterxml.jackson.core.type.TypeReference;
import com.red.circle.component.redis.service.RedisService;
import com.red.circle.other.infra.database.cache.key.RoomManagerKeys;
import com.red.circle.other.infra.database.cache.service.other.SetHotRoomCacheService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 设置置顶房间 缓存实现.
 *
 * @author pengliang on 2022/4/6
 */
@Service
@RequiredArgsConstructor
public class SetHotRoomCacheServiceImpl implements SetHotRoomCacheService {

  private final static String CACHE_LIST_KEY = "LIST";
  private final RedisService redisService;

  @Override
  public void setListCache(Object obj) {
    redisService.hashPut(
        RoomManagerKeys.SET_HOT_ROOM.name(),
        CACHE_LIST_KEY,
        obj
    );
  }

  @Override
  public <T> List<T> listCache(TypeReference<List<T>> cls) {
    return redisService.hashGet(RoomManagerKeys.SET_HOT_ROOM.name(), CACHE_LIST_KEY, cls);
  }

  @Override
  public void remove() {
    redisService.delete(RoomManagerKeys.SET_HOT_ROOM.name());
  }
}
