當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
使用SpringTask定时获取传感器设备信息并缓存到Redis
生活随笔
收集整理的這篇文章主要介紹了
使用SpringTask定时获取传感器设备信息并缓存到Redis
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1)整合:略。因為在Spring-context包中已經整合過了
2)使用:寫一個方法,然后加上規則,他就會被定時執行
/*** 項目啟動后從數據庫將各設備的信息和閾值查詢出來放入redis* 五分鐘一次*/ //0 */5 * * * ? @Scheduled(cron = "0 */5 * * * ?") public void getDeviceThresholdFromRedis() {//保證redis中是最新的數據,需要定時刪除redisTemplate.delete("deviceThreshold");Set deviceThreshold = redisTemplate.opsForHash().keys("deviceThreshold");if (deviceThreshold.size() < 1) {List<Device> deviceList = deviceDao.list(null, null, null);for (Device device : deviceList) {redisTemplate.opsForHash().put("deviceThreshold",device.getId(),device);}}System.out.println(deviceThreshold.size()); }3)注意事項:因為考慮到客戶的部署環境比較復雜,redis沒有做高可用,可能會掛掉
?
總結
以上是生活随笔為你收集整理的使用SpringTask定时获取传感器设备信息并缓存到Redis的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 定时任务框架入门
- 下一篇: SpringSession实现用户会话