Jedis

<p>After you create an ECS instance and a whitelist entry, install a Jedis client on the ECS instance and access the Redis instance from the Jedis client.</p> <p><strong><span style="font-size:18px">Prerequisites</span></strong></p> <ol> <li>You have successfully created a Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_Redis" target="_blank">Create a Redis Instance</a>. Make sure the instance is in running status.</li> <li>You have successfully created an ECS instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_ECS" target="_blank">Create an ECS Instance</a>. Make sure the instance is in running status.</li> <li>You have successfully created a whitelist entry. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/Getting_Started.Create_Whitelist" target="_blank">Create a Whitelist Entry</a>.</li> </ol> <p><strong><span style="font-size:18px">Procedures</span></strong></p> <p>1.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log in to the ECS instance.</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;a.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Log in to the <a href="https://pinganyun.com/console/ecs/overview" target="_blank">ECS Console</a>.</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;b.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the left navigation pane, click <strong>Instance</strong> to enter the <strong>Instance Management</strong> page.</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;c.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the <strong>Operations</strong> column for the target instance, click <strong>ECS Console</strong>.</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;d.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Enter the username and password.</p> <p>2.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Download and install the Jedis client and common-pool2.</p> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507140954-17d175e29f2a.png" style="height:20px; margin:0px; width:80px" />:</p> <ul> <li>You must download Jedis 2.9.0 or higher. The download address is download address.</li> <li>You must download commons-pool2 or higher versions. The download address is download address.</li> </ul> <p>3.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Connect to the Redis instance. Create a Project on the Eclipse client and execute the following codes:</p> <pre> <code>import java.util.HashSet; import java.util.Set; import org.apache.commons.pool2.impl.GenericObjectPoolConfig; import redis.clients.jedis.HostAndPort; import redis.clients.jedis.JedisCluster; public class pacloud_redis_usage {   private static JedisCluster pool = null;   public static JedisCluster getPool() {     if (pool == null) {       GenericObjectPoolConfig = new GenericObjectPoolConfig();       genericObjectPoolConfig.setMaxIdle(50); //Maximum idle connections       genericObjectPoolConfig.setMinIdle(20); //Minimum idle connections       genericObjectPoolConfig.setMaxWaitMillis(3000L);       genericObjectPoolConfig.setMaxTotal(100); //Maximum connecttions       Set&lt;HostAndPort&gt; node = new HashSet&lt;HostAndPort&gt;();       node.add(new HostAndPort("Domain-Name ", Port));  //Specify the domain name and port number of the Redis instance       pool = new JedisCluster(node, 10000, 3000, 5, "Password", genericObjectPoolConfig);  //Specify the access password displayed in the console     }     return pool;   }   public static void main(String[] args)     throws Exception   {        JedisCluster jc = getPool();        try {            jc.set("foo", "pingan yun");            System.out.println(jc.get("foo"));            }        catch (Exception e)        {            e.printStackTrace();            }        }   }</code></pre> <p><img src="https://obs-cn-shanghai.yun.pingan.com/pcp-portal/20201507140954-17d175e29f2a.png" style="height:20px; margin:0px; width:80px" />:</p> <ul> <li>Domain-Name: Access domain name of the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li> <li>Port: Port number of the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li> <li>Password: Password of the Redis instance that has been set when you create the Redis instance. For more information, see <a href="http://pinganyun.com/ssr/help/database/Redis/User_Guide.Instance_Management.View_Instance" target="_blank">View Basic Information about an Instance</a>.</li> </ul> <p><strong><span style="font-size:18px">Result</span></strong></p> <p>The system returns pingan yun, indicating that the Jedis client has been successfully connected to the Redis instance.</p> <p>&nbsp;</p>
Did the above content solve your problem? Yes No
Please complete information!

Call us

400-151-8800

Email us

cloud@pingan.com

Online customer service

Instant reply

Technical Support

cloud products