使用java操作Redis(Jedis)

导入依赖

    <dependencies>
        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>3.6.0</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>

在Linux中关闭防火墙

[root@iZbp1htnoa70qlle394f3wZ bin]# service firewalld stop

重启Redis服务

[root@iZbp1htnoa70qlle394f3wZ bin]# redis-server luoConfig/redis.conf 

编写程序测试连接是否成功

    public static void main(String[] args) {
        //创建Jedis对象
        Jedis jedis = new Jedis("47.110.248.227",6379);
        //测试
        String ping = jedis.ping();
        System.out.println(ping);
    }

测试结果

image

posted @ 2022-06-02 22:19  小罗要有出息  阅读(191)  评论(0)    收藏  举报