解决向redis添加\t被自动转义成\\t的问题,添加标志样例类配置模板
This commit is contained in:
@@ -51,24 +51,36 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
protected ServicesRequestLogService servicesRequestLogService;
|
||||
|
||||
@Autowired
|
||||
ConfigRedisService configRedisServiceimpl;
|
||||
ConfigRedisService configRedisService;
|
||||
|
||||
@RequestMapping(value = "/save", method = RequestMethod.GET)
|
||||
@ApiOperation(value = "test redis", httpMethod = "GET", response = Map.class, notes = "测试redis事务的crontroller")
|
||||
@ApiParam(value = "test redis", name = "测试redis事务的crontroller", required = true)
|
||||
public String testRedis() {
|
||||
public String testRedis(Integer type) {
|
||||
try {
|
||||
if(type==1) {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
|
||||
long id=configRedisServiceimpl.getIncrId("seq_compileid");
|
||||
long id=configRedisService.getIncrId("seq_compileid");
|
||||
//int id=2;
|
||||
map.put("cfg_id", id+"");
|
||||
map.put("is_valid", "1");
|
||||
map.put("dst_file", "/home/1234/");
|
||||
map.put("dst_file", "home");
|
||||
map.put("dst_file_md5", "fasdfdasfsdafdsafadsf");
|
||||
map.put("time_stamp", new Date().getTime() + "");
|
||||
map.put("level", "20");
|
||||
map.put("file_id",id+"");
|
||||
configRedisServiceimpl.saveConfigYSPDemoCompile(96,map);
|
||||
configRedisService.saveConfigYSPDemoCompile(96,map);
|
||||
}else {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
long id=configRedisService.getIncrId("seq_compileid");
|
||||
//int id=2;
|
||||
map.put("cfg_id", id+"");
|
||||
map.put("is_valid", "1");
|
||||
map.put("service", "100");
|
||||
map.put("description", "123"+id);
|
||||
map.put("level", "20");
|
||||
configRedisService.saveConfigYSPDemoCompile(100,map);
|
||||
}
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.nis.web.dao.impl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
@@ -10,4 +11,11 @@ public abstract class BaseRedisDao<K, V> {
|
||||
@Autowired
|
||||
protected RedisTemplate<K, V> redisTemplate;
|
||||
|
||||
// public void setRedisTemplate(RedisTemplate<K, V> redisTemplate) {
|
||||
// StringRedisSerializer stringRedisSerializer = new StringRedisSerializer();
|
||||
// redisTemplate.setKeySerializer(stringRedisSerializer);
|
||||
// redisTemplate.setValueSerializer(stringRedisSerializer);
|
||||
// this.redisTemplate = redisTemplate;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -12,8 +12,20 @@ import java.util.Map;
|
||||
*
|
||||
*/
|
||||
public interface ConfigRedisService {
|
||||
/**
|
||||
* 保存ysp样例配置接口
|
||||
* @param service 业务类型
|
||||
* @param map
|
||||
*/
|
||||
public void saveConfigYSPDemoCompile(int service, Map<String, String> map);
|
||||
|
||||
/**
|
||||
* 保存ysp配置接口
|
||||
* @param service
|
||||
* @param map
|
||||
*/
|
||||
public void saveConfigYSPCompile(int service, Map<String, String> map);
|
||||
|
||||
/**
|
||||
* 获取指定key的自增长值
|
||||
* @param key 需要自增的key
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.nis.web.service.restful;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.data.redis.support.atomic.RedisAtomicLong;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -43,18 +41,17 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
valBF.append(map.get(valStr));
|
||||
} else if (valStr.equals(" ")) {
|
||||
valBF.append(" ");
|
||||
} else {
|
||||
valBF.append(valStr.trim());
|
||||
} else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t
|
||||
valBF.append("\t");
|
||||
} else if (valStr.equals("\\n")) {
|
||||
valBF.append("\n");
|
||||
}
|
||||
}
|
||||
DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate);
|
||||
System.out.println(keyBF.toString());
|
||||
System.out.println(valBF.toString());
|
||||
|
||||
// DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(),
|
||||
// redisTemplate);
|
||||
// System.out.println(keyBF.toString());
|
||||
// System.out.println(valBF.toString());
|
||||
//redisTemplate.boundValueOps(keyBF.toString()).
|
||||
|
||||
redisTemplate.opsForValue().set(keyBF.toString(), valBF.toString());
|
||||
redisTemplate.opsForValue().set(keyBF.toString(), new String(valBF));
|
||||
// redisTemplate.boundValueOps(keyBF.toString()).set(valBF.toString());
|
||||
|
||||
}
|
||||
@@ -101,7 +98,6 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIncrId(String key) {
|
||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
||||
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
||||
@@ -112,8 +108,12 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
// atomicLong.expire(liveTime, TimeUnit.SECONDS);
|
||||
// }
|
||||
// return id;
|
||||
|
||||
return redisTemplate.boundValueOps(key).increment(1l);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void saveConfigYSPCompile(int service, Map<String, String> map) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,7 @@
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"
|
||||
default-lazy-init="true">
|
||||
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd">
|
||||
<!-- 加载配置文件,不知道为啥不能加载redis.properties的内容,先把redis.properties里面的内容放到jdbc.properties里面吧 -->
|
||||
<context:property-placeholder
|
||||
ignore-unresolvable="true" location="classpath:jdbc.properties" />
|
||||
@@ -29,8 +28,8 @@
|
||||
<bean id="connectionFactory"
|
||||
class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"
|
||||
p:host-name="${redis.host}" p:port="${redis.port}" p:pool-config-ref="poolConfig"
|
||||
p:database="0" scope="prototype" />
|
||||
<!-- p:password="" -->
|
||||
p:database="0" />
|
||||
<!-- p:password="" scope="prototype"-->
|
||||
|
||||
|
||||
<bean id="stringRedisSerializer"
|
||||
@@ -45,8 +44,4 @@
|
||||
<!-- 设置开启事务 -->
|
||||
<property name="enableTransactionSupport" value="true" />
|
||||
</bean>
|
||||
|
||||
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -127,6 +127,7 @@ jdbc.test.password=OrTu/cLwlduYPW/tmxqNgQ==
|
||||
##redis连接
|
||||
#####################################################################################################################################
|
||||
redis.host=10.0.6.228
|
||||
#redis.host=10.0.6.32
|
||||
redis.port=6379
|
||||
redis.pass=
|
||||
redis.maxIdle=10
|
||||
|
||||
@@ -3,14 +3,24 @@
|
||||
xsi:schemaLocation="http://www.w3school.com.cn maat.xsd">
|
||||
|
||||
|
||||
<p:maatType service="96;97;98;99;100;101;160;161;162;163;164;165">
|
||||
<p:maatType service="96;97;98;99;160;161;162;163">
|
||||
<p:expressions>
|
||||
<p:keyExpression>file_index_info;,;[cfg_id]</p:keyExpression>
|
||||
<p:keyExpression>EFFECTIVE_RULE;:;FILE_INDEX_INFO;,;[cfg_id]</p:keyExpression>
|
||||
<p:valueExpression>[cfg_id];\t;[is_valid];\t;[dst_file];\t;[dst_file_md5];\t;[time_stamp];&nbsp;[level];\t;[file_id];\n</p:valueExpression>
|
||||
<p:redisDB>2</p:redisDB>
|
||||
</p:expressions>
|
||||
</p:maatType>
|
||||
|
||||
<p:maatType service="100;101;164;165">
|
||||
<p:expressions>
|
||||
<p:keyExpression>EFFECTIVE_RULE;:;mark_sample;,;[cfg_id]</p:keyExpression>
|
||||
<p:valueExpression>[cfg_id];\t;[service];\t;[level];\t;[description];\t;[is_valid]</p:valueExpression>
|
||||
<p:redisDB>2</p:redisDB>
|
||||
</p:expressions>
|
||||
</p:maatType>
|
||||
|
||||
|
||||
|
||||
</p:maat>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user