After installing Redis on Linux, use Java to connect. The Java code is as follows package com.wzj.demo.test; import redis.clients.jedis.Jedis; /** * Created by wzj on 2018/3/29. */ public class RedisJava { public static void main(String[] args) { //Connect to the local Redis service Jedis jedis = new Jedis("192.168.3.45"); System.out.println("Connection successful"); //Set redis string data jedis.set("runoobkey", "www.runoob.com"); // Get the stored data and output System.out.println("The string stored in redis is: " + jedis.get("runoobkey")); } } Report the following error: Exception in thread "main" redis.clients.jedis.exceptions.JedisConnectionException: java.net.SocketException: Connection reset at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:202) at redis.clients.util.RedisInputStream.readByte(RedisInputStream.java:40) at redis.clients.jedis.Protocol.process(Protocol.java:151) 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.Jedis.set(Jedis.java:121) at com.wzj.demo.test.RedisJava.main(RedisJava.java:17) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Caused by: java.net.SocketException: Connection reset at java.net.SocketInputStream.read(SocketInputStream.java:209) at java.net.SocketInputStream.read(SocketInputStream.java:141) at java.net.SocketInputStream.read(SocketInputStream.java:127) at redis.clients.util.RedisInputStream.ensureFill(RedisInputStream.java:196) ... 12 more Use Telnet 192.168.3.45 6379 and find that the port is blocked. After searching and analyzing online, the reason is: Redis only allows local connections by default, and does not allow connections from other machines. The following modifications need to be made: (1) Modify the redis.conf file and comment out the line bind 127.0.0.1 ::1. (2) Modify the redis.conf file and set protected-mode to no (3) When starting, you need to specify the redis.conf file and execute the ./src/redis-server redis.conf command After setting up, restart the test and find that the Java code can connect normally. The above article on how to allow remote connection for Redis under Linux is all I have to share with you. I hope it can give you a reference, and I also hope that you will support 123WORDPRESS.COM. You may also be interested in:
|
<<: mysql8.0.11 winx64 manual installation and configuration tutorial
>>: WeChat applet silent login and maintenance of custom login state detailed explanation
Table of contents 1. What is an index signature? ...
Table of contents 1. Tool Introduction 2. Workflo...
The following is the code for building an ssh ser...
Copy code The code is as follows: <html> &l...
Table of contents need Core Idea Two ways to impl...
Today I will talk about a CSS special effect of h...
Data backup and restoration part 2, as follows Ba...
Deploy the project to the project site test envir...
Hexadecimal code table of various colors [Part 1] ...
Using the image service deployed by docker stack,...
I summarized the previous notes on installing MyS...
Problem Description Install nginx on Tencent Clou...
Preface <br />I have been working in the fro...
Table of contents Functionalcomponents Childcompo...
As shown in the following figure: When we use vir...