提交获取id的方法
This commit is contained in:
@@ -56,16 +56,18 @@ public class ConfigSourcesController extends BaseRestController {
|
||||
@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(String id) {
|
||||
public String testRedis() {
|
||||
try {
|
||||
Map<String, String> map = new HashMap<String, String>();
|
||||
map.put("cfg_id", id);
|
||||
|
||||
long id=configRedisServiceimpl.getIncrId("seq_compileid");
|
||||
map.put("cfg_id", id+"");
|
||||
map.put("is_valid", "1");
|
||||
map.put("dst_file", "/home/1234/");
|
||||
map.put("dst_file_md5", "fasdfdasfsdafdsafadsf");
|
||||
map.put("time_stamp", new Date().getTime() + "");
|
||||
map.put("level", "20");
|
||||
map.put("file_id",id);
|
||||
map.put("file_id",id+"");
|
||||
configRedisServiceimpl.saveConfigYSPDemoCompile(96,map);
|
||||
return "ok";
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -13,4 +13,11 @@ import java.util.Map;
|
||||
*/
|
||||
public interface ConfigRedisService {
|
||||
public void saveConfigYSPDemoCompile(int service, Map<String, String> map);
|
||||
|
||||
/**
|
||||
* 获取指定key的自增长值
|
||||
* @param key 需要自增的key
|
||||
* @return
|
||||
*/
|
||||
public Long getIncrId(String key);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@ 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;
|
||||
@@ -34,7 +36,6 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
}
|
||||
}
|
||||
StringBuffer valBF = new StringBuffer();
|
||||
//valBF.append("\"");
|
||||
String[] valSplit = maatXmlExpr.getValueExpression().split(";");
|
||||
for (String valStr : valSplit) {
|
||||
if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) {
|
||||
@@ -46,11 +47,13 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
valBF.append(valStr.trim());
|
||||
}
|
||||
}
|
||||
//valBF.append("\"");
|
||||
DynamicJedisDataBase.setRedisDataBase(maatXmlExpr.getRedisDB(), redisTemplate);
|
||||
// redisTemplate.boundValueOps(keyBF.toString()).append(valBF.toString());
|
||||
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.boundValueOps(keyBF.toString()).set(valBF.toString());
|
||||
|
||||
@@ -72,8 +75,6 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
System.out.println("\\t");
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void test() {
|
||||
|
||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
||||
@@ -100,4 +101,19 @@ public class ConfigRedisServiceimpl extends BaseRedisDao<String, String> impleme
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getIncrId(String key) {
|
||||
DynamicJedisDataBase.setRedisDataBase(2, redisTemplate);
|
||||
// RedisAtomicLong atomicLong = new RedisAtomicLong(key,
|
||||
// redisTemplate.getConnectionFactory());
|
||||
//
|
||||
// Long id = atomicLong.getAndIncrement() + 1;
|
||||
// if ((id == null || id.longValue() == 0) && liveTime > 0) {
|
||||
// atomicLong.expire(liveTime, TimeUnit.SECONDS);
|
||||
// }
|
||||
// return id;
|
||||
|
||||
return redisTemplate.boundValueOps(key).increment(1l);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user