本文整理匯總了Java中org.springframework.data.redis.core.ValueOperations類的典型用法代碼示例。如果您正苦於以下問題:Java ValueOperations類的具體用法?Java ValueOperations怎麽用?Java ValueOperations使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ValueOperations類屬於org.springframework.data.redis.core包,在下文中一共展示了ValueOperations類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addTransactionGroup
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Override
public TxGroup addTransactionGroup(String groupId,String uniqueKey, String taskId,int isGroup, String modelName) {
ValueOperations<String, String> value = redisTemplate.opsForValue();
String key = key_prefix + groupId;
String json = value.get(key);
if (StringUtils.isEmpty(json)) {
return null;
}
TxGroup txGroup = TxGroup.parser(json);
if (txGroup != null) {
TxInfo txInfo = new TxInfo();
txInfo.setModelName(modelName);
txInfo.setKid(taskId);
txInfo.setAddress(Constants.address);
txInfo.setIsGroup(isGroup);
txInfo.setUniqueKey(uniqueKey);
txGroup.addTransactionInfo(txInfo);
value.set(key, txGroup.toJsonString(), redis_save_max_time, TimeUnit.SECONDS);
return txGroup;
}
return null;
}
示例2: unlike
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Override
@Transactional(propagation = Propagation.REQUIRED)
public long unlike(Long feedId, Long uid) {
if (feedId == null || uid == null) {
return -1;
}
Like like = likeMapper.getLike(feedId, uid);
if (like == null) {
return -1;
} else {
int deleteResult = likeMapper.delete(like.getId());
if (deleteResult > 0) {
ZSetOperations<String, String> feedLikes = this.template.opsForZSet();
ValueOperations<String, String> feedCount = this.template.opsForValue();
feedLikes.remove(KEY_FEED_LIKE + feedId, Long.toString(uid));
return feedCount.increment(KEY_FEED_LIKE_COUNT + feedId, -1);
}
return -1;
}
}
示例3: user
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
/**
* 用戶菜單列表
*/
@RequestMapping("/user")
public R user() {
List<SysMenuEntity> menuList = null;
Set<String> permissions = sysMenuService.getUserPermissions(getUserId());
ValueOperations<String, String> ops = this.template.opsForValue();
String keyMenu = getUserId() + "_menuList";
if (!template.hasKey(keyMenu)) {
logger.debug("菜單從database讀取");
menuList = sysMenuService.getUserMenuList(getUserId());
ops.set(keyMenu, JSON.toJSONString(menuList));
} else {
logger.debug("菜單從redis讀取");
menuList = JSONObject.parseArray(ops.get(keyMenu),SysMenuEntity.class);
}
return R.ok().put("menuList", menuList).put("permissions", permissions);
}
示例4: testRedisConfig
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Test
public void testRedisConfig() {
ValueOperations<String, String> ops = stringRedisTemplate.opsForValue();
ops.set("test", "value");
Assert.assertEquals( "value" , ops.get("test"));
Assert.assertNull( ops.get("test2") );
ValueOperations<String, Object> ops2 = redisTemplate.opsForValue();
UserDo userDo = new UserDo();
userDo.setId(1L); userDo.setUserId("userId"); userDo.setUserName("userName");
ops2.set("testUser", userDo);
UserDo redisUser = (UserDo)ops2.get("testUser");
Assert.assertNotNull( redisUser );
Assert.assertTrue( 1L==redisUser.getId() );
Assert.assertEquals("userId", redisUser.getUserId());
Assert.assertEquals("userName", redisUser.getUserName());
}
示例5: cacheValue
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
/**
* 緩存value操作
*
* @param k key
* @param v value
* @param time time
* @return boolean
*/
@Override
public boolean cacheValue(String k, String v, long time) {
String key = KEY_PREFIX_VALUE + k;
try {
ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
valueOps.set(key, v);
if (time > 0) {
redisTemplate.expire(key, time, TimeUnit.SECONDS);
}
return true;
} catch (Throwable t) {
LOGGER.error("緩存[" + key + "]失敗, value[" + v + "]", t);
}
return false;
}
示例6: testOpsForList
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Test
public void testOpsForList(){
List<User> roles = new ArrayList<>();
User user = new com.carlos.luke.model.User(1L, "luke", 20);
roles.add(user);
ValueOperations<String, Object> opsForList = redisTemplate.opsForValue();
opsForList.set("roles", roles);
List<User> result = (List<User>) opsForList.get("roles");
System.out.println(result.get(0).getName());
}
示例7: testOpsForMap
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Test
public void testOpsForMap(){
Map<String, String> score = new HashMap<>();
score.put("stuA", "89");
score.put("stuB", "63");
score.put("stuC", "94");
score.put("stuD", "21");
ValueOperations<String, Object> opsForList = redisTemplate.opsForValue();
opsForList.set("scores", score);
Map<String, String> result = (Map<String, String>) opsForList.get("scores");
System.out.println(result.get("stuA"));
}
示例8: getStringAndUpDate
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
/**
* 獲取String緩存並更新
* @param key
* @return
*/
public T getStringAndUpDate(String key,int time){
ValueOperations<String, T> operations = redisTemplate.opsForValue();
T t = operations.get(key);
if (t!=null) operations.set(key,t,time, TimeUnit.HOURS);
return t;
}
示例9: createTransactionGroup
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Override
public TxGroup createTransactionGroup() {
String groupId = KidUtils.generateShortUuid();
TxGroup txGroup = new TxGroup();
txGroup.setStartTime(System.currentTimeMillis());
txGroup.setGroupId(groupId);
String key = key_prefix + groupId;
ValueOperations<String, String> value = redisTemplate.opsForValue();
value.set(key, txGroup.toJsonString(), redis_save_max_time, TimeUnit.SECONDS);
return txGroup;
}
示例10: checkTransactionGroup
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Override
public int checkTransactionGroup(String groupId, String taskId) {
ValueOperations<String, String> value = redisTemplate.opsForValue();
String key = key_prefix + groupId;
String json = value.get(key);
if (StringUtils.isEmpty(json)) {
key = key_prefix_notify + groupId;
json = value.get(key);
if (StringUtils.isEmpty(json)) {
return 0;
}
}
TxGroup txGroup = TxGroup.parser(json);
if(txGroup.getHasOver()==0){
long nowTime = System.currentTimeMillis();
long startTime = txGroup.getStartTime();
//超時清理數據
if(nowTime-startTime>(redis_save_max_time*1000)){
redisTemplate.delete(key);
return 0;
}
return -1;
}
boolean res = txGroup.getState() == 1;
if(!res) {
return 0;
}
for (TxInfo info : txGroup.getList()) {
if (info.getKid().equals(taskId)) {
return info.getNotify()==0?1:0;
}
}
return 0;
}
示例11: closeTransactionGroup
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Override
public boolean closeTransactionGroup(String groupId,int state) {
ValueOperations<String, String> value = redisTemplate.opsForValue();
String key = key_prefix + groupId;
String json = value.get(key);
if (StringUtils.isEmpty(json)) {
return false;
}
final TxGroup txGroup = TxGroup.parser(json);
txGroup.setState(state);
txGroup.setHasOver(1);
transactionConfirmService.confirm(txGroup);
return true;
}
示例12: dealTxGroup
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
@Override
public void dealTxGroup(TxGroup txGroup, boolean hasOk) {
String key = key_prefix + txGroup.getGroupId();
if (!hasOk) {
//未通知成功
if (txGroup.getState() == 1) {
ValueOperations<String, String> value = redisTemplate.opsForValue();
String newKey = key_prefix_notify + txGroup.getGroupId();
value.set(newKey, txGroup.toJsonString());
}
}
redisTemplate.delete(key);
}
示例13: get
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
/**
* 讀取緩存
*
* @param key
* @return
*/
public static Object get(final String key) {
Object result = null;
ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
result = operations.get(key);
return result;
}
示例14: set
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
/**
* 寫入緩存
*
* @param key
* @param value
* @return
*/
public static boolean set(final String key, Object value) {
boolean result = false;
try {
ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
operations.set(key, value);
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例15: getUser
import org.springframework.data.redis.core.ValueOperations; //導入依賴的package包/類
public User getUser(Integer id) {
ValueOperations valueOperations = redisTemplate.opsForValue();
System.out.println(JSON.toJSON(valueOperations.get(USER_PREFIX + id)));
User user = (User) valueOperations.get(USER_PREFIX + id);
return user;
}