org.springframework.data.redis.connection.RedisConnection.del()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(246)

本文整理了Java中org.springframework.data.redis.connection.RedisConnection.del方法的一些代码示例,展示了RedisConnection.del的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RedisConnection.del方法的具体详情如下:
包路径:org.springframework.data.redis.connection.RedisConnection
类名称:RedisConnection
方法名:del

RedisConnection.del介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public void remove(String name, byte[] key) {
  Assert.notNull(name, "Name must not be null!");
  Assert.notNull(key, "Key must not be null!");
  execute(name, connection -> connection.del(key));
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Long del(byte[]... keys) {
  return convertAndReturn(delegate.del(keys), identityConverter);
}

代码示例来源:origin: spring-projects/spring-data-redis

private Long doUnlock(String name, RedisConnection connection) {
  return connection.del(createCacheLockKey(name));
}

代码示例来源:origin: spring-projects/spring-data-redis

/**
 * Removes all indexes.
 */
public void removeAllIndexes(String keyspace) {
  Set<byte[]> potentialIndex = connection.keys(toBytes(keyspace + ":*"));
  if (!potentialIndex.isEmpty()) {
    connection.del(potentialIndex.toArray(new byte[potentialIndex.size()][]));
  }
}

代码示例来源:origin: apache/nifi

@Override
public void onComponentRemoved(final String componentId) throws IOException {
  withConnection(redisConnection -> {
    final byte[] key = getComponentKey(componentId).getBytes(StandardCharsets.UTF_8);
    redisConnection.del(key);
    return true;
  });
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Boolean delete(K key) {
  byte[] rawKey = rawKey(key);
  Long result = execute(connection -> connection.del(rawKey), true);
  return result != null && result.intValue() == 1;
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public Long delete(Collection<K> keys) {
  if (CollectionUtils.isEmpty(keys)) {
    return 0L;
  }
  byte[][] rawKeys = rawKeys(keys);
  return execute(connection -> connection.del(rawKeys), true);
}

代码示例来源:origin: apache/nifi

@Override
public <K> boolean remove(final K key, final Serializer<K> keySerializer) throws IOException {
  return withConnection(redisConnection -> {
    final byte[] k = serialize(key, keySerializer);
    final long numRemoved = redisConnection.del(k);
    return numRemoved > 0;
  });
}

代码示例来源:origin: spring-projects/spring-security-oauth

public void removeRefreshToken(String tokenValue) {
  byte[] refreshKey = serializeKey(REFRESH + tokenValue);
  byte[] refreshAuthKey = serializeKey(REFRESH_AUTH + tokenValue);
  byte[] refresh2AccessKey = serializeKey(REFRESH_TO_ACCESS + tokenValue);
  byte[] access2RefreshKey = serializeKey(ACCESS_TO_REFRESH + tokenValue);
  RedisConnection conn = getConnection();
  try {
    conn.openPipeline();
    conn.del(refreshKey);
    conn.del(refreshAuthKey);
    conn.del(refresh2AccessKey);
    conn.del(access2RefreshKey);
    conn.closePipeline();
  } finally {
    conn.close();
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public void clean(String name, byte[] pattern) {
  Assert.notNull(name, "Name must not be null!");
  Assert.notNull(pattern, "Pattern must not be null!");
  execute(name, connection -> {
    boolean wasLocked = false;
    try {
      if (isLockingCacheWriter()) {
        doLock(name, connection);
        wasLocked = true;
      }
      byte[][] keys = Optional.ofNullable(connection.keys(pattern)).orElse(Collections.emptySet())
          .toArray(new byte[0][]);
      if (keys.length > 0) {
        connection.del(keys);
      }
    } finally {
      if (wasLocked && isLockingCacheWriter()) {
        doUnlock(name, connection);
      }
    }
    return "OK";
  });
}

代码示例来源:origin: apache/nifi

@Override
public long removeByPattern(final String regex) throws IOException {
  return withConnection(redisConnection -> {
    long deletedCount = 0;
    final List<byte[]> batchKeys = new ArrayList<>();
    // delete keys in batches of 1000 using the cursor
    final Cursor<byte[]> cursor = redisConnection.scan(ScanOptions.scanOptions().count(100).match(regex).build());
    while (cursor.hasNext()) {
      batchKeys.add(cursor.next());
      if (batchKeys.size() == 1000) {
        deletedCount += redisConnection.del(getKeys(batchKeys));
        batchKeys.clear();
      }
    }
    // delete any left-over keys if some were added to the batch but never reached 1000
    if (batchKeys.size() > 0) {
      deletedCount += redisConnection.del(getKeys(batchKeys));
      batchKeys.clear();
    }
    return deletedCount;
  });
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public void deleteAllOf(String keyspace) {
  redisOps.execute((RedisCallback<Void>) connection -> {
    connection.del(toBytes(keyspace));
    new IndexWriter(connection, converter).removeAllIndexes(asString(keyspace));
    return null;
  });
}

代码示例来源:origin: spring-projects/spring-security-oauth

conn.get(accessKey);
conn.get(authKey);
conn.del(accessKey);
conn.del(accessToRefreshKey);
conn.del(authKey);
List<Object> results = conn.closePipeline();
byte[] access = (byte[]) results.get(0);
  byte[] clientId = serializeKey(CLIENT_ID_TO_ACCESS + authentication.getOAuth2Request().getClientId());
  conn.openPipeline();
  conn.del(authToAccessKey);
  conn.sRem(unameKey, access);
  conn.sRem(clientId, access);
  conn.del(serialize(ACCESS + key));
  conn.closePipeline();

代码示例来源:origin: spring-projects/spring-security-oauth

private void removeAccessTokenUsingRefreshToken(String refreshToken) {
  byte[] key = serializeKey(REFRESH_TO_ACCESS + refreshToken);
  List<Object> results = null;
  RedisConnection conn = getConnection();
  try {
    conn.openPipeline();
    conn.get(key);
    conn.del(key);
    results = conn.closePipeline();
  } finally {
    conn.close();
  }
  if (results == null) {
    return;
  }
  byte[] bytes = (byte[]) results.get(0);
  String accessToken = deserializeString(bytes);
  if (accessToken != null) {
    removeAccessToken(accessToken);
  }
}

代码示例来源:origin: spring-projects/spring-data-redis

/**
 * Removes a key from all available indexes.
 *
 * @param key must not be {@literal null}.
 */
public void removeKeyFromIndexes(String keyspace, Object key) {
  Assert.notNull(key, "Key must not be null!");
  byte[] binKey = toBytes(key);
  byte[] indexHelperKey = ByteUtils.concatAll(toBytes(keyspace + ":"), binKey, toBytes(":idx"));
  for (byte[] indexKey : connection.sMembers(indexHelperKey)) {
    DataType type = connection.type(indexKey);
    if (DataType.ZSET.equals(type)) {
      connection.zRem(indexKey, binKey);
    } else {
      connection.sRem(indexKey, binKey);
    }
  }
  connection.del(indexHelperKey);
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public <T> T delete(Object id, String keyspace, Class<T> type) {
  byte[] binId = toBytes(id);
  byte[] binKeyspace = toBytes(keyspace);
  T o = get(id, keyspace, type);
  if (o != null) {
    byte[] keyToDelete = createKey(asString(keyspace), asString(id));
    redisOps.execute((RedisCallback<Void>) connection -> {
      connection.del(keyToDelete);
      connection.sRem(binKeyspace, binId);
      new IndexWriter(connection, converter).removeKeyFromIndexes(asString(keyspace), binId);
      return null;
    });
  }
  return o;
}

代码示例来源:origin: spring-projects/spring-data-redis

@Override
public void onMessage(Message message, @Nullable byte[] pattern) {
  if (!isKeyExpirationMessage(message)) {
    return;
  }
  byte[] key = message.getBody();
  byte[] phantomKey = ByteUtils.concat(key, converter.getConversionService().convert(KeyspaceIdentifier.PHANTOM_SUFFIX, byte[].class));
  Map<byte[], byte[]> hash = ops.execute((RedisCallback<Map<byte[], byte[]>>) connection -> {
    Map<byte[], byte[]> hash1 = connection.hGetAll(phantomKey);
    if (!CollectionUtils.isEmpty(hash1)) {
      connection.del(phantomKey);
    }
    return hash1;
  });
  Object value = converter.read(Object.class, new RedisData(hash));
  String channel = !ObjectUtils.isEmpty(message.getChannel())
      ? converter.getConversionService().convert(message.getChannel(), String.class) : null;
  RedisKeyExpiredEvent event = new RedisKeyExpiredEvent(channel, key, value);
  ops.execute((RedisCallback<Void>) connection -> {
    connection.sRem(converter.getConversionService().convert(event.getKeyspace(), byte[].class), event.getId());
    new IndexWriter(connection, converter).removeKeyFromIndexes(event.getKeyspace(), event.getId());
    return null;
  });
  publishEvent(event);
}

代码示例来源:origin: spring-projects/spring-data-redis

byte[] objectKey = createKey(rdo.getKeyspace(), rdo.getId());
boolean isNew = connection.del(objectKey) == 0;
  connection.del(phantomKey);
  connection.hMSet(phantomKey, rdo.getBucket().rawMap());
  connection.expire(phantomKey, rdo.getTimeToLive() + 300);

代码示例来源:origin: spring-projects/spring-integration

@SuppressWarnings("unchecked")
@Test
@RedisAvailable
public void testMGetCommand() {
  RedisConnection connection = this.getConnectionFactoryForTest().getConnection();
  byte[] value1 = "bar1".getBytes();
  byte[] value2 = "bar2".getBytes();
  connection.set("foo1".getBytes(), value1);
  connection.set("foo2".getBytes(), value2);
  this.mgetCommandChannel.send(MessageBuilder.withPayload(new String[] { "foo1", "foo2" }).build());
  Message<?> receive = this.replyChannel.receive(1000);
  assertNotNull(receive);
  assertThat((List<byte[]>) receive.getPayload(), Matchers.contains(value1, value2));
  connection.del("foo1".getBytes(), "foo2".getBytes());
}

代码示例来源:origin: spring-projects/spring-integration

@Before
public void setup() {
  RedisConnectionFactory jcf = getConnectionFactoryForTest();
  jcf.getConnection().del(this.queueName);
  this.inboundGateway.start();
}

相关文章

微信公众号

最新文章

更多

RedisConnection类方法