Browse Source

@IPU_FIXBUG_2021@示例代码优化

weihf 3 years ago
parent
commit
a0b873ba5a

+ 12 - 6
ipu-rest-demo/src/main/java/com/ai/ipu/server/demo/control/cache/RedisController.java

@ -37,16 +37,18 @@ public class RedisController {
37 37
		try {
38 38
			cache = CacheFactory.getCache(connName);
39 39
			result.put("result", cache.get(key));
40
			LOGGER.debug(key + " is " + result.getString("result"));			
40
			LOGGER.debug(key + " is " + result.getString("result"));	
41
			CacheFactory.commit(connName);
41 42
		} catch (Exception e)
42 43
		{
44
			CacheFactory.rollback(connName);
43 45
			String errorMsg = "从redis中获取" + key + "错误:" + e.toString();
44 46
			LOGGER.error(errorMsg);
45 47
			result.put("result", errorMsg);
46 48
		}finally {
47 49
			//使用完redis需要将连接关闭/释放
48 50
			if (cache != null)
49
				cache.close();
51
				CacheFactory.close(connName, cache);
50 52
		}
51 53
		return result;
52 54
	}
@ -65,16 +67,18 @@ public class RedisController {
65 67
		try {
66 68
			cache = CacheFactory.getCache(connName);
67 69
			result.put("result", cache.put(key, value));
68
			LOGGER.debug(result.getString("result"));				
70
			LOGGER.debug(result.getString("result"));	
71
			CacheFactory.commit(connName);
69 72
		} catch (Exception e)
70 73
		{
74
			CacheFactory.rollback(connName);
71 75
			String errorMsg = "从redis中获取" + key + "错误:" + e.toString();
72 76
			LOGGER.error(errorMsg);
73 77
			result.put("result", errorMsg);
74 78
		}finally {
75 79
			//使用完redis需要将连接关闭/释放
76 80
			if (cache != null)
77
				cache.close();
81
				CacheFactory.close(connName, cache);
78 82
		}
79 83
		return result;
80 84
	}
@ -91,16 +95,18 @@ public class RedisController {
91 95
		try {
92 96
			cache = CacheFactory.getCache(connName);
93 97
			result.put("result", cache.remove(key));
94
			LOGGER.debug(result.getString("result"));		
98
			LOGGER.debug(result.getString("result"));	
99
			CacheFactory.commit(connName);
95 100
		} catch (Exception e)
96 101
		{
102
			CacheFactory.rollback(connName);
97 103
			String errorMsg = "从redis中获取" + key + "错误:" + e.toString();
98 104
			LOGGER.error(errorMsg);
99 105
			result.put("result", errorMsg);
100 106
		}finally {
101 107
			//使用完redis需要将连接关闭/释放
102 108
			if (cache != null)
103
				cache.close();
109
				CacheFactory.close(connName, cache);
104 110
		}
105 111
		return result;
106 112
	}

+ 2 - 1
ipu-rest-demo/src/main/java/com/ai/ipu/server/demo/control/dfs/MinIOController.java

@ -5,6 +5,7 @@ import org.springframework.stereotype.Controller;
5 5
import org.springframework.web.bind.annotation.RequestMapping;
6 6
import org.springframework.web.bind.annotation.ResponseBody;
7 7

8
import com.ai.ipu.basic.file.FileUtil;
8 9
import com.ai.ipu.data.JMap;
9 10
import com.ai.ipu.data.impl.JsonMap;
10 11
import com.ai.ipu.server.demo.service.MinIOServiceImpl;
@ -126,7 +127,7 @@ public class MinIOController {
126 127
		String bucketName = param.getString("bucketName", DEFAULT_BUCKET_NAME);
127 128
		String localFile = LOCAL_FILE_PATH + "/2.txt";
128 129
		JMap result = new JsonMap();
129
		result.put("result", service.uploadFile(DEFAULT_DFS_NAME, bucketName, localFile, "text/plain"));
130
		result.put("result", service.uploadFile(DEFAULT_DFS_NAME, bucketName, localFile, FileUtil.getFileExtension(localFile)));
130 131
		return result;
131 132
	}
132 133
}