Redis JDBC

 1、导入依赖:
       
            redis.clients
            jedis
            4.4.3
        
2、连接JDBC
public class JedisDemo05 {
    public static void main(String[] args) {
        //建立redis的连接:
        Jedis jedis = new Jedis("192.168.226.100", 7000);
        // string类型存储结构
        String name = jedis.set("name", "tom");
        System.out.println(name);
        //根据key获取对应的value
        String s = jedis.get("name");
        System.out.println(s);
        String mset = jedis.mset("age","18","age1","19");
        List mget = jedis.mget("age", "age1");
        System.out.println(mget);



        //list存储结构
        //向集合中添加元素,从左端开始添加元素
        long clazz = jedis.lpush("clazz", "clazz1", "clazz2", "clazz3");
        List clazz1 = jedis.lrange("clazz", 0, -1);
        System.out.println(clazz1);


        //set存储结构:
        long sadd = jedis.sadd("gender", "男");
        Set gender = jedis.smembers("gender");
        System.out.println(gender);


        //zset存储结构:
        long zadd = jedis.zadd("score", 90, "math");
        Double zscore = jedis.zscore("score", "math");
        System.out.println(zscore);


        //hash存储结构:
        HashMap map = new HashMap<>();
        map.put("name","tom");
        map.put("age","19");
        map.put("address","宇宙");
        long hset = jedis.hset("个人信息", map);
        Map hgetAll = jedis.hgetAll("个人信息");
        System.out.println(hgetAll);


        //关闭连接:
        jedis.close();
    }
}

你可能感兴趣的:(Redis,7.0.0,redis,java,mybatis)