You see the Technical Museum of Java to use Redis

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/dyq1995/article/details/102753819

Java uses Redis

installation

Before you start using Redis in Java, we need to ensure that services and Java redis redis drive already installed on your machine and normal use Java. Java installation configuration can refer to our Java development environment configuration Let's install Java redis drive:

  • First you need to download the driver package, make sure to download the latest driver package.
  • This package contains the driver in your classpath

Connection to redis service


import redis.clients.jedis.Jedis;
 
public class RedisJava {
    public static void main(String[] args) {
        //连接本地的 Redis 服务
        Jedis jedis = new Jedis("localhost");
        System.out.println("连接成功");
        //查看服务是否运行
        System.out.println("服务正在运行: "+jedis.ping());
    }
}

Java compile the above procedures to ensure that the driver package path is correct.

连接成功
服务正在运行: PONG

Redis Java String (String) Examples


import redis.clients.jedis.Jedis;
 
public class RedisStringJava {
    public static void main(String[] args) {

Guess you like

Origin blog.csdn.net/dyq1995/article/details/102753819