/** * Executed wrapped command upon {@link RedisClusterConnection}. * * @param callback must not be {@literal null}. * @return execution result. Can be {@literal null}. */ @Nullable public <T> T execute(RedisClusterCallback<T> callback) { Assert.notNull(callback, "ClusterCallback must not be null!"); RedisClusterConnection connection = template.getConnectionFactory().getClusterConnection(); try { return callback.doInRedis(connection); } finally { connection.close(); } } }
@Override public RedisClusterConnection getClusterConnection() { System.out.println("getClusterConnection"); return redisConnectionFactory.getClusterConnection(); }
/** * Executed wrapped command upon {@link RedisClusterConnection}. * * @param callback must not be {@literal null}. * @return execution result. Can be {@literal null}. */ @Nullable public <T> T execute(RedisClusterCallback<T> callback) { Assert.notNull(callback, "ClusterCallback must not be null!"); RedisClusterConnection connection = template.getConnectionFactory().getClusterConnection(); try { return callback.doInRedis(connection); } finally { connection.close(); } } }
@PostMapping(value = "/setRedisCluster") public Problem setRedisCluster() { redisConnectionFactory.getClusterConnection().stringCommands() .set("key".getBytes(), "value".getBytes()); stringRedisTemplate.opsForValue().set("stringKey", "stringValue"); return Problem.builder().with("data", "success").build(); }
/** * Executed wrapped command upon {@link RedisClusterConnection}. * * @param callback must not be {@literal null}. * @return execution result. Can be {@literal null}. */ @Nullable public <T> T execute(RedisClusterCallback<T> callback) { Assert.notNull(callback, "ClusterCallback must not be null!"); RedisClusterConnection connection = template.getConnectionFactory().getClusterConnection(); try { return callback.doInRedis(connection); } finally { connection.close(); } } }
@GetMapping(value = "/getRedisCluster") public Problem getRedisCluster() { byte[] bytes = redisConnectionFactory.getClusterConnection().stringCommands() .get("key".getBytes()); if (bytes != null) { String value = new String(bytes, StandardCharsets.UTF_8); String stringValue = stringRedisTemplate.opsForValue().get("stringKey"); return Problem.builder().with("data", value + "_" + stringValue).build(); } else { return Problem.valueOf(Status.BAD_REQUEST); } }