Java Connection Example

Last updated: 2021-02-25 15:07:09

Preparations before running:
Download the Jedis client.

Sample code:

import redis.clients.jedis.Jedis;

public class HelloRedis {

  public static void main(String[] args) {
            /**Enter your Redis instance private IP, port number, instance ID, and password in the following parameters*/
            String host = "192.xx.xx.195";
            int port = 6379;
           String instanceid = "crs-09xxxqv";
            String password = "123ad6aq";
            // Connect to Redis
            Jedis jedis = new Jedis(host, port);
            // Authenticate
            jedis.auth(instanceid + ":" + password);

            /**You can start manipulating the Redis instance. For more information, see */
            // Set the Key
            jedis.set("redis", "tencent");
            System.out.println("set key redis suc, value is: tencent");
            // Get the Key
            String value = jedis.get("redis");
            System.out.println("get key redis is: " + value);

            // Close and exit
        } catch (Exception e) {

Execution results: