1.注解配置
import io.rebloom.client.Client;
import redis.clients.jedis.JedisPool;
@EnableCaching
@Configuration
public class RedisConfig {
@Autowired
private JedisPool jedisPool;
@Bean
public Client client() {
Client client = new Client(jedisPool);
return client;
}
@Bean
public JedisPool jedisPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxIdle(30);
config.setMaxTotal(200);
config.setMaxWaitMillis(30000);
config.setTestOnBorrow(true);
JedisPool jedisPool = new JedisPool(config, "10.121.198.101", 6379, 30000);
return jedisPool;
}
}
2.使用
//插入
client.add("name","javaboy-"+i);
//判断是否存在
boolean exists = client.exists("name", "javaboy-99999");
3.依赖
<dependency>
<groupId>com.redislabs</groupId>
<artifactId>jrebloom</artifactId>
<version>1.2.0</version>
</dependency>
4.注解式
@Configuration
public class RedisConfig {
@Autowired
private Environment environment;
@Bean
public Client client() {
Client client = new Client(jedisPool());
return client;
}
public JedisPool jedisPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxIdle(environment.getProperty("spring.redis.jedis.pool.max-idle", Integer.class));
config.setMaxTotal(200);
config.setMaxWaitMillis(environment.getProperty("spring.redis.timeout", Integer.class));
config.setTestOnBorrow(true);
JedisPool jedisPool = new JedisPool(config, environment.getProperty("spring.redis.host"),
environment.getProperty("spring.redis.port", Integer.class), environment.getProperty("spring.redis.timeout", Integer.class));
return jedisPool;
}
}