问剑白玉京 2023-08-10 09:42 采纳率: 76.9%
浏览 4
已结题

idea连接服务器端redis失败

在使用idea连接服务器端的redis时失败!

服务器操作系统 CentOS8
redis版本 7.x.x

按照网上的教程,已经将

  • protected-mode 设置成 no

img

  • 将bind注释掉

img

  • daemonize 设置成yes

img

  • 设置了密码

img

  • 服务器安全组也开放了6379端口

img

  • 防火墙也打开了6379

img

使用idea连接时报错
pom.xml

    <!--导包-->
    <dependencies>
        <!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>4.4.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.alibaba.fastjson2/fastjson2 -->
        <dependency>
            <groupId>com.alibaba.fastjson2</groupId>
            <artifactId>fastjson2</artifactId>
            <version>2.0.38</version>
        </dependency>

    </dependencies>
public class TestPing {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("47.96.39.104", 6379);
        jedis.auth("123456");
        System.out.println(jedis.ping());
    }
}

报错

img

  • 写回答

3条回答 默认 最新

  • 代码调试大神 2023-08-10 09:46
    关注

    密码写了否,试试

    import redis.clients.jedis.Jedis;
    import redis.clients.jedis.JedisPool;
    import redis.clients.jedis.JedisPoolConfig;
    
    public class RedisConnectionExample {
        public static void main(String[] args) {
            // Set the Redis server host and port
            String redisHost = "your_redis_host";
            int redisPort = 6379;
    
            // Set the Redis server password (if any)
            String redisPassword = "your_redis_password";
    
            // Configure the connection pool
            JedisPoolConfig poolConfig = new JedisPoolConfig();
            JedisPool jedisPool = new JedisPool(poolConfig, redisHost, redisPort, 0, redisPassword);
    
            // Create a new Jedis instance from the pool
            try (Jedis jedis = jedisPool.getResource()) {
                // Perform Redis operations
                jedis.set("key", "value");
                String result = jedis.get("key");
                System.out.println("Retrieved value: " + result);
            } catch (Exception e) {
                // Handle exception
                e.printStackTrace();
            } finally {
                // Close the Jedis pool
                jedisPool.close();
            }
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

问题事件

  • 系统已结题 8月18日
  • 已采纳回答 8月10日
  • 创建了问题 8月10日

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程