本文整理了Java中org.springframework.data.redis.core.RedisTemplate.keys
方法的一些代码示例,展示了RedisTemplate.keys
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisTemplate.keys
方法的具体详情如下:
包路径:org.springframework.data.redis.core.RedisTemplate
类名称:RedisTemplate
方法名:keys
暂无
代码示例来源:origin: yu199195/Raincat
@Override
public void removeCommitTxGroup() {
final Set<String> keys = redisTemplate.keys(Constant.REDIS_KEYS);
keys.parallelStream().forEach(key -> {
final Map<Object, TxTransactionItem> entries = redisTemplate.opsForHash().entries(key);
final Collection<TxTransactionItem> values = entries.values();
final boolean present = values.stream()
.anyMatch(item -> item.getStatus() != TransactionStatusEnum.COMMIT.getCode());
if (!present) {
redisTemplate.delete(key);
}
});
}
代码示例来源:origin: yu199195/Raincat
@Override
public void removeRollBackTxGroup() {
final Set<String> keys = redisTemplate.keys(Constant.REDIS_KEYS);
keys.parallelStream().forEach(key -> {
final Map<Object, TxTransactionItem> entries = redisTemplate.opsForHash().entries(key);
final Collection<TxTransactionItem> values = entries.values();
final Optional<TxTransactionItem> any =
values.stream().filter(item -> item.getRole() == TransactionRoleEnum.START.getCode()
&& item.getStatus() == TransactionStatusEnum.ROLLBACK.getCode())
.findAny();
if (any.isPresent()) {
redisTemplate.delete(key);
}
});
}
代码示例来源:origin: yu199195/Raincat
rangeKeys = Sets.newHashSet(txTransactionQuery.getTxGroupId());
} else {
keys = redisTemplate.keys(CommonConstant.REDIS_KEYS);
rangeKeys = redisTemplate.opsForZSet()
.range(CommonConstant.REDIS_KEY_SET, start, end - 1);
代码示例来源:origin: bill1012/AdminEAP
@Override
public Set<String> keys(final String pattern) {
return redisTemplate.keys(pattern);
}
代码示例来源:origin: spring-projects/spring-integration
@Override
protected Collection<?> doListKeys(String keyPattern) {
Assert.hasText(keyPattern, "'keyPattern' must not be empty");
return this.redisTemplate.keys(keyPattern);
}
代码示例来源:origin: spring-projects/spring-integration
@ManagedAttribute
public int getMessageGroupCount() {
Set<Object> keys = this.redisTemplate.keys(this.beanName + ":*");
return keys == null ? 0 : keys.size();
}
代码示例来源:origin: zhangxd1989/springboot-dubbox
/**
* 查询在以keyPatten的所有 key
*
* @param keyPatten the key patten
* @return the set
*/
public Set<String> keys(final String keyPatten) {
return redisTemplate.execute((RedisCallback<Set<String>>) connection -> redisTemplate.keys(keyPatten + "*"));
}
代码示例来源:origin: spring-projects/spring-integration
private List<String> sortedKeys(String groupId) {
Set<Object> keys = this.getRedisTemplate().keys(groupId == null ? (this.getBeanName() + ":*") : (groupId + "*"));
List<String> list = new LinkedList<>();
if (keys != null) {
for (Object key : keys) {
Assert.isInstanceOf(String.class, key);
list.add((String) key);
}
Collections.sort(list, this.keysComparator);
}
return list;
}
代码示例来源:origin: spring-projects/spring-integration
private Set<Object> narrowedKeys() {
Set<Object> keys = this.getRedisTemplate().keys(this.getBeanName() + ":*");
Set<Object> narrowedKeys = new HashSet<>();
if (keys != null) {
for (Object key : keys) {
Assert.isInstanceOf(String.class, key);
String keyString = (String) key;
int lastIndexOfColon = keyString.lastIndexOf(":");
if (keyString.indexOf(":") != lastIndexOfColon) {
narrowedKeys.add(keyString.substring(0, lastIndexOfColon));
}
else {
narrowedKeys.add(key);
}
}
}
return narrowedKeys;
}
代码示例来源:origin: spring-projects/spring-integration
@ManagedAttribute
public int getMessageCountForAllMessageGroups() {
Set<?> keys = this.redisTemplate.keys(this.beanName + ":*");
if (keys == null) {
return 0;
}
int count = 0;
for (Object key : keys) {
count += this.messageGroupSize(key);
}
return count;
}
代码示例来源:origin: zhangxd1989/springboot-dubbox
/**
* 查询在这个时间段内即将过期的key
*
* @param key the key
* @param time the time
* @return the list
*/
public List<String> willExpire(final String key, final long time) {
final List<String> keysList = new ArrayList<>();
redisTemplate.execute((RedisCallback<List<String>>) connection -> {
Set<String> keys = redisTemplate.keys(key + "*");
for (String key1 : keys) {
Long ttl = connection.ttl(key1.getBytes(DEFAULT_CHARSET));
if (0 <= ttl && ttl <= 2 * time) {
keysList.add(key1);
}
}
return keysList;
});
return keysList;
}
代码示例来源:origin: spring-projects/spring-integration
private void assertNoLocksAfterTest() throws Exception {
int n = 0;
while (n++ < 100 && this.template.keys("aggregatorWithRedisLocksTests:*").size() > 0) {
Thread.sleep(100);
}
assertEquals(0, this.template.keys("aggregatorWithRedisLocksTests:*").size());
}
代码示例来源:origin: zhangxd1989/springboot-dubbox
/**
* 根据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;
});
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@RedisAvailable
public void testLockSingleGroup() throws Exception {
this.releaseStrategy.reset(1);
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 1));
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 1));
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
assertEquals(1, this.template.keys("aggregatorWithRedisLocksTests:*").size());
this.releaseStrategy.latch1.countDown();
assertNotNull(this.out.receive(10000));
assertEquals(1, this.releaseStrategy.maxCallers.get());
this.assertNoLocksAfterTest();
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@RedisAvailable
public void testLockThreeGroups() throws Exception {
this.releaseStrategy.reset(3);
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 1));
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 1));
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 2));
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 2));
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 3));
Executors.newSingleThreadExecutor().execute(asyncSend("bar", 2, 3));
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
assertEquals(3, this.template.keys("aggregatorWithRedisLocksTests:*").size());
this.releaseStrategy.latch1.countDown();
this.releaseStrategy.latch1.countDown();
this.releaseStrategy.latch1.countDown();
assertNotNull(this.out.receive(10000));
assertNotNull(this.out.receive(10000));
assertNotNull(this.out.receive(10000));
assertEquals(3, this.releaseStrategy.maxCallers.get());
this.assertNoLocksAfterTest();
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
}
代码示例来源:origin: spring-projects/spring-integration
@Before
@After
public void setup() {
this.template = this.createTemplate();
Set<String> keys = template.keys("aggregatorWithRedisLocksTests:*");
for (String key : keys) {
template.delete(key);
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@RedisAvailable
@Repeat(10)
public void testDistributedAggregator() throws Exception {
this.releaseStrategy.reset(1);
Executors.newSingleThreadExecutor().execute(asyncSend("foo", 1, 1));
Executors.newSingleThreadExecutor().execute(() -> {
try {
in2.send(new GenericMessage<String>("bar", stubHeaders(2, 2, 1)));
}
catch (Exception e) {
exception = e;
}
});
assertTrue(this.releaseStrategy.latch2.await(10, TimeUnit.SECONDS));
assertEquals(1, this.template.keys("aggregatorWithRedisLocksTests:*").size());
this.releaseStrategy.latch1.countDown();
assertNotNull(this.out.receive(10000));
assertEquals(1, this.releaseStrategy.maxCallers.get());
this.assertNoLocksAfterTest();
assertNull("Unexpected exception:" + (this.exception != null ? this.exception.toString() : ""), this.exception);
}
代码示例来源:origin: wyh-spring-ecosystem-student/spring-boot-student
@Override
public void clear() {
logger.debug("清空缓存");
try {
Set<String> keys = redisTemplate.keys("*:" + this.id + "*");
if (!CollectionUtils.isEmpty(keys)) {
redisTemplate.delete(keys);
}
} catch (Exception e) {
}
}
代码示例来源:origin: chengzhx76/weixin-shop-spring-cloud
/**
* 批量删除key
* @param pattern
*/
public void removePattern(final String pattern) {
Set<Serializable> keys = redisTemplate.keys(pattern);
if (keys.size() > 0) {
redisTemplate.delete(keys);
}
}
代码示例来源:origin: Nepxion/Aquarius
private void clear(List<String> compositeWildcardKeys) {
for (String compositeWildcardKey : compositeWildcardKeys) {
Set<String> keys = redisTemplate.keys(compositeWildcardKey);
for (String k : keys) {
redisTemplate.delete(k);
}
}
}
}
内容来源于网络,如有侵权,请联系作者删除!