import java.sql.*; public class RedisJDBCExample { public static void main(String[] args) { try (Connection connection = DriverManager.getConnection("jdbc:redis://localhost:6379")) { try (Statement statement = connection.createStatement()) { try (ResultSet resultSet = statement.executeQuery("GET mykey")) { if (resultSet.next()) { String value = resultSet.getString(1); System.out.println("Value: " + value); } } } try (Statement statement = connection.createStatement()) { int updatedRows = statement.executeUpdate("SET mykey 'Hello, Redis!'"); System.out.println("Updated rows: " + updatedRows); } try (Statement statement = connection.createStatement()) { connection.setAutoCommit(false); statement.executeUpdate("SET key1 'value1'"); statement.executeUpdate("SET key2 'value2'"); connection.commit(); } } catch (SQLException e) { e.printStackTrace(); } } }


上一篇:
下一篇:
切换中文