当前位置: 首页>>代码示例>>Java>>正文


Java RedisCallback类代码示例

本文整理汇总了Java中org.springframework.data.redis.core.RedisCallback的典型用法代码示例。如果您正苦于以下问题:Java RedisCallback类的具体用法?Java RedisCallback怎么用?Java RedisCallback使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RedisCallback类属于org.springframework.data.redis.core包,在下文中一共展示了RedisCallback类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: updatetag

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public Integer updatetag(Integer tId) {
    //标签
    List<Tag> tags = tagMapper.getAllTags();
    JsonArray jsonArray = new JsonArray();
    for (Tag tag : tags) {
        List<Blog> blogs = tagMapper.getblogbytagid(tag.gettId());
        String str = tag.gettName() + " " + "(" + String.valueOf(blogs.size()) + ")";
        KeyAndValue keyAndValue = new KeyAndValue();
        keyAndValue.setKey(tag.gettName());
        keyAndValue.setValue(str);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("key", tag.gettId());
        jsonObject.addProperty("value", str);
        jsonArray.add(jsonObject);
    }
    boolean result = redisTemplate.execute((RedisCallback<Boolean>) connection -> {
        RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
        connection.set(serializer.serialize("biaoqian"), serializer.serialize(jsonArray.toString()));
        return true;
    });
    return tId;
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:25,代码来源:TagServiceImpl.java

示例2: updateAll

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public void updateAll() {
    
    try {
        final List<Viapp> list = appDao.getAllApp();
        logger.info("BeginNewAddAppToRedis...");
        long start = System.currentTimeMillis();
        redisTemplate.execute(new RedisCallback<Object>() {  
            @Override  
            public Object doInRedis(RedisConnection connection)  
                    throws DataAccessException {
                connection.flushDb();
                //connection.multi();
                commonRedis.saveCommonRedis(list,connection);
               // connection.exec();
                return null;  
            }  
        });  
        logger.info("redis init finish cost:{}ms!", System.currentTimeMillis() - start);
        
    }catch(Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:zhaoxi1988,项目名称:sjk,代码行数:25,代码来源:DataObserableImpl.java

示例3: put

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public void put(Object key, Object value) {
    final String keyf = (String) key;
    final Object valuef = value;
    final long liveTime = 86400;

    redisTemplate.execute(new RedisCallback<Long>() {
        public Long doInRedis(RedisConnection connection) throws DataAccessException {
            byte[] keyb = keyf.getBytes();
            byte[] valueb = toByteArray(valuef);
            connection.set(keyb, valueb);
            if (liveTime > 0) {
                connection.expire(keyb, liveTime);
            }
            return 1L;
        }
    });
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:19,代码来源:RedisCache.java

示例4: evict

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public void evict(Object key) {
    final String keyf = (String) key;
    redisTemplate.execute(new RedisCallback<Long>() {
        public Long doInRedis(RedisConnection connection) throws DataAccessException {
            return connection.del(keyf.getBytes());
        }
    });
}
 
开发者ID:Zephery,项目名称:newblog,代码行数:10,代码来源:RedisCache.java

示例5: getKeysValues

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
/**
 * 根据key获取对象
 *
 * @param keyPatten the key patten
 * @return the keys values
 */
public Map<String, String> getKeysValues(final String keyPatten) {
    LOGGER.info("[redisTemplate redis]  getValues()  patten={} ", keyPatten);
    return redisTemplate.execute((RedisCallback<Map<String, String>>) connection -> {
        RedisSerializer<String> serializer = getRedisSerializer();
        Map<String, String> maps = new HashMap<>();
        Set<String> keys = redisTemplate.keys(keyPatten + "*");
        for (String key : keys) {
            byte[] bKeys = serializer.serialize(key);
            byte[] bValues = connection.get(bKeys);
            String value = serializer.deserialize(bValues);
            maps.put(key, value);
        }
        return maps;
    });
}
 
开发者ID:ruyangit,项目名称:angit,代码行数:22,代码来源:RedisRepository.java

示例6: getServerServiceRequests

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public List<RequestStatics> getServerServiceRequests(final String serverIp, final String serviceId) throws Exception {
    return stringRedisTemplate.execute(new RedisCallback<List<RequestStatics>>() {
        public List<RequestStatics> doInRedis(RedisConnection connection) throws DataAccessException {
            String k = Constants.REDIS_SERVER_PREFIX + serverIp + "_" + serviceId;
            StringRedisConnection conn = ((StringRedisConnection)connection);
            Set<StringTuple> callers = conn.zRangeByScoreWithScores(k, Long.MIN_VALUE, Long.MAX_VALUE);
            if (callers.isEmpty()){
                return Collections.EMPTY_LIST;
            }
            List<RequestStatics> res = new ArrayList<RequestStatics>();
            for (StringTuple tuple:callers){
                Double score = tuple.getScore();
                String value = tuple.getValueAsString();
                RequestStatics statics = new RequestStatics();
                statics.setTime(score.longValue());
                statics.setCount(Integer.parseInt(value));
                res.add(statics);
            }
            Collections.sort(res);
            return res;
        }
    });
}
 
开发者ID:wuzhongdehua,项目名称:fksm,代码行数:25,代码来源:GraphcServiceImpl.java

示例7: getString

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
public static String getString(final String key, final Long seconds) {
    String result = (String) redisTemplate.execute(new RedisCallback<String>() {
        @Override
        public String doInRedis(RedisConnection connection) throws DataAccessException {
            try {
                byte[] byteKey = key.getBytes("utf-8");
                byte[] value = connection.get(byteKey);
                if (value == null) {
                    return null;
                }
                if (seconds != null) {
                    connection.expire(byteKey, seconds);
                }
                return new String(value, "utf-8");
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("不支持的编码类型utf-8", e);
            }
        }
    }, true, false);
    return result;
}
 
开发者ID:yangshuai0711,项目名称:dingding-app-server,代码行数:22,代码来源:RedisUtil.java

示例8: hSetString

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
public static void hSetString(final String key, final String field, final String value, final Long seconds) {
    redisTemplate.execute(new RedisCallback() {
        @Override
        public Object doInRedis(RedisConnection connection) throws DataAccessException {
            try {
                byte[] byteKey = key.getBytes("utf-8");
                connection.hSet(byteKey, field.getBytes("utf-8"), value.getBytes("utf-8"));
                if (seconds != null) {
                    connection.expire(byteKey, seconds);
                }
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException("不支持的编码类型utf-8", e);
            }
            return null;
        }
    }, true, true);
}
 
开发者ID:yangshuai0711,项目名称:dingding-app-server,代码行数:18,代码来源:RedisUtil.java

示例9: getServerServiceCodes

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public List<CodeStatics> getServerServiceCodes(final String serverIp, final String serviceId) throws Exception {
    return stringRedisTemplate.execute(new RedisCallback<List<CodeStatics>>() {
        public List<CodeStatics> doInRedis(RedisConnection connection) throws DataAccessException {
            String k = Constants.REDIS_SERVER_CODE_PREFIX + serverIp + "_" + serviceId;
            StringRedisConnection conn = ((StringRedisConnection)connection);
            Set<StringTuple> callers = conn.zRangeByScoreWithScores(k, Long.MIN_VALUE, Long.MAX_VALUE);
            if (callers.isEmpty()){
                return Collections.EMPTY_LIST;
            }
            List<CodeStatics> res = new ArrayList<CodeStatics>();
            for (StringTuple tuple:callers){
                Double score = tuple.getScore();
                String value = tuple.getValueAsString();
                CodeStatics statics = new CodeStatics();
                statics.setTime(score.longValue());
                statics.setScore(Double.parseDouble(value));
                res.add(statics);
            }
            Collections.sort(res);
            return res;
        }
    });
}
 
开发者ID:wuzhongdehua,项目名称:fksm,代码行数:25,代码来源:GraphcServiceImpl.java

示例10: clear

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@ManagedOperation(description = "Clear the store")
@Override
public void clear() {
    valueOperations.getOperations().execute(new RedisCallback<List<byte[]>>() {
        @Override
        public List<byte[]> doInRedis(RedisConnection connection) throws DataAccessException {
            List<byte[]> binaryKeys = new ArrayList<>();
            Cursor<byte[]> cursor = connection.scan(ScanOptions.scanOptions().match("*" + createRedisKey("*")).build());

            while (cursor.hasNext()) {
                byte[] key = cursor.next();
                binaryKeys.add(key);
            }
            if (binaryKeys.size() > 0) {
                connection.del(binaryKeys.toArray(new byte[][]{}));
            }
            return binaryKeys;
        }
    });
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:RedisStringIdempotentRepository.java

示例11: loadRemoteCacheKeys

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected Set<String> loadRemoteCacheKeys() {
	return (Set<String>) template.execute(new RedisCallback<Set<String>>() {

		@Override
		public Set<String> doInRedis(RedisConnection connection) throws DataAccessException {

			// we are using the ~keys postfix as defined in RedisCache#setName
			Set<byte[]> keys = connection.keys(template.getKeySerializer().serialize("*~keys"));
			Set<String> cacheKeys = new LinkedHashSet<String>();

			if (!CollectionUtils.isEmpty(keys)) {
				for (byte[] key : keys) {
					cacheKeys.add(template.getKeySerializer().deserialize(key).toString().replace("~keys", ""));
				}
			}

			return cacheKeys;
		}
	});
}
 
开发者ID:panguixiang,项目名称:my-spring-cache-redis,代码行数:22,代码来源:MyRedisCacheManager.java

示例12: put

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void put(final Object key, final Object value,final Long expireTime) {

	final byte[] keyBytes = computeKey(key);
	final byte[] valueBytes = convertToBytesIfNecessary(redisTemplate.getValueSerializer(), value);

	redisTemplate.execute(new RedisCallback<Object>() {
		public Object doInRedis(RedisConnection connection) throws DataAccessException {
			waitForLock(connection);
			connection.multi();
			connection.set(keyBytes, valueBytes);
			connection.zAdd(setName, 0, keyBytes);
			if (expireTime!=null && expireTime!=0L) {
				connection.expire(keyBytes, expireTime);
				connection.expire(setName, expireTime);
			}
			connection.exec();
			return null;
		}
	}, true);
}
 
开发者ID:panguixiang,项目名称:my-spring-cache-redis,代码行数:22,代码来源:MyRedisCache.java

示例13: update

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public boolean update(final String key, final String value) {
    if (get(key) == null) {
        throw new NullPointerException("数据行不存在, key = " + key);
    }
    boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
        public Boolean doInRedis(RedisConnection connection)
                throws DataAccessException {
            RedisSerializer<String> serializer = getRedisSerializer();
            byte[] keyStr = serializer.serialize(key);
            byte[] valueStr = serializer.serialize(value);
            connection.set(keyStr, valueStr);
            return true;
        }
    });
    return result;
}
 
开发者ID:bill1012,项目名称:AdminEAP,代码行数:18,代码来源:RedisDaoImpl.java

示例14: deleteTieBaImageTypeOne

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
/**
     * 删除历史数据
     * 根据key值找到图片的名称
     */
    @Deprecated
    public void deleteTieBaImageTypeOne() {
        redisTemplate.execute(new RedisCallback<Object>() {
            public Object doInRedis(RedisConnection redisConnection) throws DataAccessException {
                byte[] imageKey = getByte(TieBaImageIdMessageListener.TIEBA_CONTENT_IMAGE_KEY + "*");
                long beginTime = System.currentTimeMillis();
                Set<byte[]> keys = redisConnection.keys(imageKey);
                log.info("模糊查询耗时:{}", (System.currentTimeMillis() - beginTime) + "ms");
                //判断key
                for (byte[] key : keys) {
                    try {
                        byte[] image = redisConnection.get(key);
                        List<String> imageUrlList = JSONObject.parseObject(image, List.class);
//                            qiNiuUtil.deleteByList(imageUrlList);
                        qiNiuUtil.getDeleteBlockingDeque().put(imageUrlList);
                    } catch (Exception e) {
                        log.error("删除图片失败!key {}", WebmagicService.getString(key));
                    }
                }
                return null;
            }
        });
    }
 
开发者ID:ggj2010,项目名称:javabase,代码行数:28,代码来源:WebmagicService.java

示例15: getServerServiceCosts

import org.springframework.data.redis.core.RedisCallback; //导入依赖的package包/类
@Override
public List<CostsStatics> getServerServiceCosts(final String serverIp, final String serviceId) throws Exception {
    return stringRedisTemplate.execute(new RedisCallback<List<CostsStatics>>() {
        public List<CostsStatics> doInRedis(RedisConnection connection) throws DataAccessException {
            String k = Constants.REDIS_SERVER_COSTS_PREFIX + serverIp + "_" + serviceId;
            StringRedisConnection conn = ((StringRedisConnection)connection);
            Set<StringTuple> callers = conn.zRangeByScoreWithScores(k, Long.MIN_VALUE, Long.MAX_VALUE);
            if (callers.isEmpty()){
                return Collections.EMPTY_LIST;
            }
            List<CostsStatics> res = new ArrayList<CostsStatics>();
            for (StringTuple tuple:callers){
                Double score = tuple.getScore();
                String value = tuple.getValueAsString();
                CostsStatics statics = new CostsStatics();
                statics.setTime(score.longValue());
                statics.setCosts(Long.parseLong(value));
                res.add(statics);
            }
            Collections.sort(res);
            return res;
        }
    });
}
 
开发者ID:wuzhongdehua,项目名称:fksm,代码行数:25,代码来源:GraphcServiceImpl.java


注:本文中的org.springframework.data.redis.core.RedisCallback类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。