Using Redis for Java

Source: Internet
Author: User

Redis installation skipped

First import the Jedis.jar package

1. Connect to Redis Service

Write a simple program:

 package   Com.fpc.Test;  import   Redis.clients.jedis.Jedis;  public  class   Manipulateredis { public  static  void   main (string[] args) {//  Redis service to connect 10.0.20.251  Jedis Jedis                = new  Jedis ("10.0.20.251" );  //  See if the service is running  System.out.println (    "Service is running:" + jedis.ping ()); }}

Note: The next 2 main pit points:

1.Redis To configure the next redis.conf file

What do you want to configure? Configure the IP address for which it listens

2. The second thing to note is that the redis-server starts with a parameter

If you do not add--protected-mode No,java run the report error:

Exception in thread "main" Redis.clients.jedis.exceptions.JedisDataException:DENIED Redis are running inprotectedmode becauseprotectedMode is enabled, no bind address was specified, no authentication password are requested to clients. Inch ThisMode connections is only accepted from the loopbackInterface. If you want-to-connect from external computers to Redis-adopt one of the following solutions:1) Just disableprotectedMode sending the command ' CONFIG SET protected-mode No ' from the loopbackInterfaceBy connecting-to-Redis from the same host the server is running, however make sure Redis are not publicly accessible from I NternetifYou DoSo. Use CONFIG REWRITE ThisChange permanent. 2) Alternatively you can just disable theprotectedMode by editing the Redis configuration file, and setting theprotectedmode option to ' No ', and then restarting the server. 3) If You started the server manually just forTesting, restart it with the '--protected-mode no ' option. 4) Setup A bind address or an authentication password. Note:you only need to DoOne of the above things in order forThe server to start accepting connections from the outside. At Redis.clients.jedis.Protocol.processError (Protocol.java:127) at Redis.clients.jedis.Protocol.process (Protocol.java:161) at Redis.clients.jedis.Protocol.read (Protocol.java:215) at Redis.clients.jedis.Connection.readProtocolWithCheckingBroken (Connection.java:340) at redis.clients.jedis.Connection.getStatusCodeReply (Connection.java:239) at redis.clients.jedis.BinaryJedis.ping (Binaryjedis.java:196) at Com.fpc.Test.ManipulateRedis.main (Manipulateredis.java:11)

Results of normal operation:

Using Redis for Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.