Redis教程

redisson使用

本文主要是介绍redisson使用,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

pom:

<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>3.15.6</version>
</dependency>

  配置类

package com.aila.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenzhichao
 * @date 2021/6/18 15:18
 */
@Configuration
public class RedissonConfig {

    @Bean
    public RedissonClient redisson(){
        Config config = new Config();
        config.useSingleServer().setAddress(("redis://192.168.101.25:6379")).setDatabase(10);
        RedissonClient redissonClient = Redisson.create(config);
        return redissonClient;
    }
}

test类

import com.aila.MyBootApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.redisson.api.RKeys;
import org.redisson.api.RedissonClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;

/**
 * @author chenzhichao
 * @date 2021/6/18 15:09
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MyBootApplication.class)
public class MyTestYy {
    @Resource
    private RedissonClient redisson;
    @Test
    public void test(){
        RKeys keys = redisson.getKeys();
        System.out.println(keys);
    }
}

  结果

org.redisson.RedissonKeys@52f8a6f4

  后续 继续

 

这篇关于redisson使用的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!