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


Java ValueOperations.get方法代碼示例

本文整理匯總了Java中org.springframework.data.redis.core.ValueOperations.get方法的典型用法代碼示例。如果您正苦於以下問題:Java ValueOperations.get方法的具體用法?Java ValueOperations.get怎麽用?Java ValueOperations.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.data.redis.core.ValueOperations的用法示例。


在下文中一共展示了ValueOperations.get方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: 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

示例7: 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

示例8: initfiltercode

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 初始化敏感詞列表
 * */
private void initfiltercode()
{
	ValueOperations<String, Object> redisOpt = redisTemplate.opsForValue();
	if(redisTemplate.hasKey(sensitiveKey)){
		keysMap=(HashMap)redisOpt.get(sensitiveKey);
	}else{
		addKeywords(getAllProperties());//構建二叉樹
		redisOpt.set(sensitiveKey, keysMap);
	}
}
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:14,代碼來源:KeywordFilter.java

示例9: 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

示例10: likeUserCount

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
@Override
public long likeUserCount(Long feedId) {
	if (feedId == null) {
		return -1;
	}
	ValueOperations<String, String> feedCount = this.template.opsForValue();
	String result = feedCount.get(KEY_FEED_LIKE_COUNT + feedId);
	if (StringUtils.isEmpty(result)) {
		return -1;
	}
	return Long.parseLong(result);
}
 
開發者ID:iqinghe,項目名稱:pcc-like,代碼行數:13,代碼來源:LikeServiceImpl.java

示例11: logoutToken

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 退出token
 * 
 * @param pd
 * @return
 */
@RequestMapping(value = "/logoutToken")
@ResponseBody
public PageData logoutToken() {
	try {
		String userToken = this.getRequest().getHeader("userKey");// 從header中獲取
		String phoneMac =  this.getRequest().getHeader("mac");// 從header中獲取
		if (StringUtils.isNotBlank(userToken) && StringUtils.isNotBlank(phoneMac)) {
			// 獲取redis值,判斷token是否存在和用戶登錄mac是否一致
			if (redisTemplate.hasKey(userToken)) {
				ValueOperations<String, Object> redisOpt = redisTemplate.opsForValue();
				PageData userPd = (PageData)redisOpt.get(userToken);
				String userMac = userPd.getString("loginMac");
				if (userMac.equals(phoneMac)) {
					redisTemplate.delete(userToken);
					return WebResult.requestSuccess();
				} else {
					return WebResult.requestFailed(502, "token已失效", null);
				}
			} else {
				return WebResult.requestFailed(502, "token已失效", null);
			}
		} else {
			return WebResult.requestFailed(500, "參數不正確", null);
		}
	} catch (Exception e) {
		e.printStackTrace();
		return WebResult.requestFailed(400, "係統錯誤,請聯係管理員", null);
	}
}
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:36,代碼來源:AppUserLoginRestful.java

示例12: queryUUID

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 輪訓UUID
 * 
 * @param pd
 * @return
 */
@RequestMapping(value = "/queryUUID")
@ResponseBody
public PageData queryUUID(@RequestBody PageData pd) {
	try {
		// 判斷二維碼狀態
		String UUID = pd.getString("uuid");
		if (StringUtils.isNotBlank(UUID)) {
			PageData optionPageData = new PageData();
			ValueOperations<String, Object> redisOpt = redisTemplate.opsForValue();
			// 獲取二維碼掃描狀態
			String redisUUID = String.join("", redisKeyPre, UUID);
			if (redisTemplate.hasKey(redisUUID)) {
				PageData optionPd = (PageData) redisOpt.get(redisUUID);
				String uuidStatic = optionPd.getString("option");
				optionPageData.put("option", uuidStatic);
				// 獲取用戶信息
				String userToken=optionPd.getString("userToken");
				if (StringUtils.isNotBlank(userToken)) {
					PageData userObj = (PageData)redisOpt.get(optionPd.getString("userToken"));
					optionPageData.put("token", userToken);
					optionPageData.put("userInfo", JSON.toJSONString(userObj.get("userInfo")));
				}
				return WebResult.requestSuccess(optionPageData);
			} else {
				return WebResult.requestFailed(509, "二維碼已過期!", null);
			}
		} else {
			return WebResult.requestFailed(500, "參數不正確", null);
		}
	} catch (Exception e) {
		e.printStackTrace();
		return WebResult.requestFailed(400, "係統錯誤,請聯係管理員", null);
	}
}
 
開發者ID:noseparte,項目名稱:Spring-Boot-Server,代碼行數:41,代碼來源:AppUserLoginRestful.java

示例13: getValue

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 獲取緩存
 *
 * @param k key
 * @return string
 */
@Override
public String getValue(String k) {
    try {
        ValueOperations<String, String> valueOps = redisTemplate.opsForValue();
        return valueOps.get(KEY_PREFIX_VALUE + k);
    } catch (Throwable t) {
        LOGGER.error("獲取緩存失敗key[" + KEY_PREFIX_VALUE + k + ", Codeor[" + t + "]");
    }
    return null;
}
 
開發者ID:xiaomoinfo,項目名稱:SpringBootUnity,代碼行數:17,代碼來源:CommonRedisDaoImpl.java

示例14: get

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 讀取緩存
 *
 * @param key
 * @return
 */
public Object get(final String key) {
    Object result = null;
    ValueOperations<Serializable, Object> operations = redisTemplate
            .opsForValue();
    result = operations.get(key);
    return result;
}
 
開發者ID:crossoverJie,項目名稱:SSM,代碼行數:14,代碼來源:RedisUtil.java

示例15: getValue

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
public String getValue(String key) throws RedisNotFoundException{
	ValueOperations<String, String> ops = this.redisTemplate.opsForValue();
	if(this.redisTemplate.hasKey(key))
		return ops.get(key);
	
	throw new RedisNotFoundException("Key: " + key + " not found.");
}
 
開發者ID:felipeg48,項目名稱:redis-examples,代碼行數:8,代碼來源:SimpleRedisService.java


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