package com.zy.omp.common.redis; import com.alibaba.fastjson.JSON; import com.zy.omp.common.Constant; import com.zy.omp.model.Location; import org.springframework.data.redis.core.RedisTemplate; import javax.annotation.Resource; /** * 设备最新的位置信息,存储在Redis缓存中 * 弃用 * * @author yang xiao kun * create on 2021/2/8 */ //@Component @Deprecated public class DeviceLatestLocationManager { @Resource private RedisTemplate redisTemplate; /** * 将最新位置信息保存至redis中 * * @param entity 位置信息 */ public void saveLocation(Location entity) { redisTemplate.boundHashOps(Constant.REDIS_LOCATION).put(entity.getDeviceId(), JSON.toJSONString(entity)); } /** * 获取设备最新位置信息 * * @param deviceId 设备ID */ public Location getLocation(String deviceId) { Object json = redisTemplate.boundHashOps(Constant.REDIS_LOCATION).get(deviceId); if (json == null) return null; return JSON.parseObject(json.toString(), Location.class); } }