bind <redis-server IP> port <redis-server port> daemonize yes pidfile /var/run/redis_<port>.pid loglevel notice logfile /var/log/redis/redis_<port>.log ... slaveof <master IP> <master port> import io.redis.jdbc.RedisConnection; import io.redis.jdbc.RedisDataSource; public class Example { public static void main(String[] args) { RedisDataSource dataSource = new RedisDataSource(); dataSource.setUrl("jdbc:redis://<redis-server IP>:<redis-server port>/database"); try (RedisConnection connection = dataSource.getConnection()) { connection.setAutoCommit(false); connection.setReadOnly(true); connection.prepareStatement("SELECT * FROM example").executeQuery(); connection.setAutoCommit(true); connection.setReadOnly(false); connection.prepareStatement("INSERT INTO example (id, name) VALUES (1, 'ExampleData')").executeUpdate(); } catch (Exception e) { e.printStackTrace(); } } }


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