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


Java ValueOperations.set方法代碼示例

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


在下文中一共展示了ValueOperations.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

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

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

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

示例8: set

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 寫入緩存
 *
 * @param key
 * @param value
 * @return
 */
public static boolean set(final String key, Object value, Long expireTime) {
    boolean result = false;
    try {
        ValueOperations<Serializable, Object> operations = redisTemplate.opsForValue();
        operations.set(key, value);
        redisTemplate.expire(key, expireTime, TimeUnit.SECONDS);

        result = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
開發者ID:MIYAOW,項目名稱:MI-S,代碼行數:21,代碼來源:RedisUtil.java

示例9: login

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 登錄
 * @param param 用戶名或手機號phone
 * @return 登錄成功後返回用戶基本信息
 * @since  1.0
 */
@PostMapping(path = "/login")
public BaseModel<UserEntity> login(@RequestBody LoginReq param) {

    BaseModel<UserEntity> userRes = new BaseModel<>();
    String key = RedisKeys.concat(RedisKeys.USER_LOGIN_FAILD, param.getName());
    ValueOperations<String, String> faildCountOps = redisTemplate.opsForValue();
    String faildCount = faildCountOps.get(key);
    int faild = 0;
    if (!StringUtils.isEmpty(faildCount)) {
        faild = Integer.parseInt(faildCount);
    }
    if (faild > 5) {
        return userRes.setResult(LoginCmdResult.LOGIN_PASSWORD_LOCK);
    }
    
    // 改為:用戶名或手機號皆可登錄
    SearchCriteria<IMUser> userSearchCriteria = new SearchCriteria<>();
    userSearchCriteria.add(JpaRestrictions.or(JpaRestrictions.eq("name", param.getName(), false),
            JpaRestrictions.eq("phone", param.getName(), false)));
    userSearchCriteria.add(JpaRestrictions.ne("status", DBConstant.USER_STATUS_LEAVE, false));
    List<IMUser> users = userRepository.findAll(userSearchCriteria);
    
    if (users.isEmpty()) {
        logger.debug("用戶{}登錄失敗", param.getName());
        return userRes.setResult(LoginCmdResult.LOGIN_NOUSER);
    }

    IMUser user = users.get(0);

    if (passwordEncoder.matches(param.getPassword(), user.getPassword())) {
        // 密碼正確
        UserEntity userEntity = new UserEntity();
        userEntity.setId(user.getId());
        userEntity.setMainName(user.getNick());
        userEntity.setAvatar(user.getAvatar());
        userEntity.setCreated(user.getCreated());
        userEntity.setDepartmentId(user.getDepartId());
        userEntity.setPeerId(user.getId());
        userEntity.setPhone(user.getPhone());
        userEntity.setRealName(user.getName());
        userEntity.setStatus(user.getStatus());
        userEntity.setGender(user.getSex());
        userEntity.setUpdated(user.getUpdated());
        userEntity.setEmail(user.getEmail());
        userEntity.setPinyinName(user.getDomain());
        userEntity.setSignInfo(user.getSignInfo());
        userRes.setData(userEntity);

        // 如果登陸成功,則清除錯誤嘗試限製
        if (faild > 0) {
            redisTemplate.delete(key);
        }
    } else {

        // 密碼錯誤,記錄一次登陸失敗
        faildCountOps.set(key, String.valueOf(++faild), 30, TimeUnit.MINUTES);
        return userRes.setResult(LoginCmdResult.LOGIN_NOUSER);
    }
    return userRes;
}
 
開發者ID:ccfish86,項目名稱:sctalk,代碼行數:67,代碼來源:LoginServiceController.java

示例10: persistImageCaptcha

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
public void persistImageCaptcha(String sid,String capText){
    StringRedisTemplate template= redisConfig.getTemplate();
    String format = imageCaptchaFormat(sid);
    ValueOperations<String,String> obj =  template.opsForValue();
    obj.set(format,capText.toLowerCase());
    template.expire(format , getImageTimeOut(), TimeUnit.MINUTES);
}
 
開發者ID:Nbsaw,項目名稱:miaohu,代碼行數:8,代碼來源:CaptchaUtils.java

示例11: persistPhoneCaptcha

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
public void persistPhoneCaptcha(String phone , String code){
    StringRedisTemplate template = getTemplate();
    String format = phoneCaptchaFormat(phone);
    ValueOperations<String,String> obj = getTemplate().opsForValue();
    obj.set(format,code.toLowerCase());
    template.expire(format ,getPhoneTimeOut(), TimeUnit.MINUTES);
}
 
開發者ID:Nbsaw,項目名稱:miaohu,代碼行數:8,代碼來源:CaptchaUtils.java

示例12: putObject

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
/**
 * 向redis緩存中放數據
 *
 * @param key
 * @param value
 */
@Override
public void putObject(Object key, Object value) {
    String strKey = "";
    if (!(key instanceof String)) {
        strKey = Objects.toString(key);
    }
    ValueOperations operations = getRedisTemplate().opsForValue();
    operations.set(strKey, value, EXPIRE_TIME_IN_MINUTES, TimeUnit.MINUTES);
}
 
開發者ID:davichi11,項目名稱:my-spring-boot-project,代碼行數:16,代碼來源:RedisCache.java

示例13: putKey

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
@Override
public void putKey(String modelName, String uniqueKey, String key) {
    String val = modelName + "#" + uniqueKey;
    ValueOperations<String, String> operations = redisTemplate.opsForValue();
    operations.set(key_prefix + key, val);
    operations.set(val_prefix + val, key);
}
 
開發者ID:1991wangliang,項目名稱:sds,代碼行數:8,代碼來源:RedisServiceImpl.java

示例14: run

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
@Override
public void run(String... args) throws Exception {
	ValueOperations<String, String> ops = this.template.opsForValue();
	String key = "spring.boot.redis.test";
	if (!this.template.hasKey(key)) {
		ops.set(key, "foo");
	}
	System.out.println("Found key " + key + ", value=" + ops.get(key));
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:10,代碼來源:SampleRedisApplication.java

示例15: testMailAndRedis

import org.springframework.data.redis.core.ValueOperations; //導入方法依賴的package包/類
@RequestMapping(value = "/testMailAndRedis")
@ResponseBody
public void testMailAndRedis(){
	ValueOperations<String, String> valueOperations =  this.redisTemplate.opsForValue();
	valueOperations.set("donggege", "東哥哥真棒", 259200l, TimeUnit.MILLISECONDS);
	smtpMailService.sendTextMail("[email protected]","[email protected]", "PUSHIO", "PUSHIO發郵件測試", "東哥哥真棒");
}
 
開發者ID:summerDp,項目名稱:dpCms,代碼行數:8,代碼來源:AccountCtrl.java


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