优化redis存储航班信息,改用map类型。避免不必要的网络传输。
This commit is contained in:
+20
-50
@@ -1,9 +1,10 @@
|
||||
package com.gzzn.omms.msgexchangeapi.service.flightInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -39,71 +40,40 @@ public class FlightInfoServiceImpl implements IFlightInfoService {
|
||||
.getSCHD()
|
||||
.getFLTR();
|
||||
|
||||
for(SCHD.FLTR fltr : lsFltr)
|
||||
{
|
||||
Boolean result = redisSet(fltr);
|
||||
if(result == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}//end for
|
||||
|
||||
return true;
|
||||
Map<String, Object> mapFltr = new HashMap();
|
||||
for(FLTR fltr : lsFltr)
|
||||
{
|
||||
mapFltr.put(fltr.getFLID().toString(), fltr);
|
||||
}
|
||||
return redisService.hmset(redisKey, mapFltr);
|
||||
} //end function
|
||||
|
||||
|
||||
@Override
|
||||
public SCHD.FLTR getByFlid(String flid) {
|
||||
SCHD.FLTR fltr = (SCHD.FLTR) redisGet(flid);
|
||||
SCHD.FLTR fltr = (SCHD.FLTR) redisService.hget(redisKey, flid);
|
||||
return fltr;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean saveFltr(SCHD.FLTR fltr) {
|
||||
return redisSet(fltr);
|
||||
return redisService.hset(redisKey, fltr.getFLID().toString(),(Object)fltr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 重新包装的set
|
||||
* @param fltr
|
||||
* @return
|
||||
*/
|
||||
private boolean redisSet(SCHD.FLTR fltr)
|
||||
{
|
||||
return redisService.set(redisKey + fltr.getFLID(), fltr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重新包装的get
|
||||
* @param flid
|
||||
* @return
|
||||
*/
|
||||
private Object redisGet(String flid)
|
||||
{
|
||||
return redisService.get(redisKey + flid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 情况所有动态航班信息
|
||||
*/
|
||||
private void removeAll()
|
||||
{
|
||||
Set<String> keys = redisService.keys(redisKey + "*");
|
||||
redisService.del(keys);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<SCHD.FLTR> findAll() {
|
||||
Set<String> keys = redisService.keys(redisKey + "*");
|
||||
|
||||
List<SCHD.FLTR> lsResult = new ArrayList();
|
||||
keys.forEach(key->{
|
||||
SCHD.FLTR fltr = (SCHD.FLTR) redisService.get(key);
|
||||
lsResult.add(fltr);
|
||||
});
|
||||
Map<Object,Object> mapResult = redisService.hmget(redisKey);
|
||||
if(mapResult == null)
|
||||
{
|
||||
throw new RuntimeException("findAll fltr from redis fail");
|
||||
}
|
||||
|
||||
Collection<Object> valueCollection = mapResult.values();
|
||||
List<SCHD.FLTR> lsResult = new ArrayList(valueCollection);
|
||||
|
||||
return lsResult;
|
||||
}//end method
|
||||
@@ -111,7 +81,7 @@ public class FlightInfoServiceImpl implements IFlightInfoService {
|
||||
|
||||
@Override
|
||||
public boolean deleteFltr(FLTR fltr) {
|
||||
redisService.del(Arrays.asList(redisKey + fltr.getFLID()));
|
||||
redisService.hdel(redisKey, fltr.getFLID());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user