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