Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Redis in Linux to allow remote connections

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How do I use Redis in Linux to allow remote connections? In view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.

After Linux has installed Redis, 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 succeeded"); / / set redis string data jedis.set ("runoobkey", "www.runoob.com") / / get the stored data and output System.out.println ("redis stored string is:" + jedis.get ("runoobkey"));}}

The following error is reported:

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 (NativeMethod) 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

Using Telnet 192.168.3.45 6379, the port was found to be impassable.

Through online search and analysis, the reason is that Redis only allows local connections by default, and does not allow other machines to connect. You need to make the following modifications:

(1) modify the redis.conf file to comment out the line bind 127.0.0.1:: 1.

(2) modify the redis.conf file. 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

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

This is the answer to the question about how to use Redis in Linux to allow remote connection. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report