當前位置: 首頁>>代碼示例>>Java>>正文


Java ValueOperations類代碼示例

本文整理匯總了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;
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:23,代碼來源:TxManagerServiceImpl.java

示例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;
	}
}
 
開發者ID:iqinghe,項目名稱:pcc-like,代碼行數:21,代碼來源:LikeServiceImpl.java

示例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);
}
 
開發者ID:guolf,項目名稱:pds,代碼行數:21,代碼來源:SysMenuController.java

示例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());
	
}
 
開發者ID:chxfantasy,項目名稱:micro-service-sample,代碼行數:22,代碼來源:RedisTest.java

示例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;
}
 
開發者ID:xiaomoinfo,項目名稱:SpringBootUnity,代碼行數:24,代碼來源:CommonRedisDaoImpl.java

示例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());
    
}
 
開發者ID:alamby,項目名稱:upgradeToy,代碼行數:15,代碼來源:RedisTest.java

示例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"));
}
 
開發者ID:alamby,項目名稱:upgradeToy,代碼行數:14,代碼來源:RedisTest.java

示例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;
}
 
開發者ID:ChinaLHR,項目名稱:JavaQuarkBBS,代碼行數:12,代碼來源:RedisService.java

示例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;
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:12,代碼來源:TxManagerServiceImpl.java

示例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;
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:38,代碼來源:TxManagerServiceImpl.java

示例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;
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:15,代碼來源:TxManagerServiceImpl.java

示例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);
}
 
開發者ID:1991wangliang,項目名稱:tx-lcn,代碼行數:15,代碼來源:TxManagerServiceImpl.java

示例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;
}
 
開發者ID:MIYAOW,項目名稱:MI-S,代碼行數:13,代碼來源:RedisUtil.java

示例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;
}
 
開發者ID:MIYAOW,項目名稱:MI-S,代碼行數:19,代碼來源:RedisUtil.java

示例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;
}
 
開發者ID:Lengchuan,項目名稱:SpringBoot-Study,代碼行數:8,代碼來源:UserDao.java


注:本文中的org.springframework.data.redis.core.ValueOperations類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。