🔖 redisson 示例

pull/1/head
Zhang Peng 2018-06-19 14:58:35 +08:00
parent 0fe9339872
commit 4de0a023cc
3 changed files with 61 additions and 0 deletions

View File

@ -16,6 +16,7 @@
<spring.version>4.3.13.RELEASE</spring.version>
<logback.version>1.2.3</logback.version>
<jedis.version>2.9.0</jedis.version>
<redisson.version>3.7.2</redisson.version>
<junit.version>4.12</junit.version>
</properties>
@ -25,6 +26,10 @@
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
</dependency>
<!-- database end -->
<!-- log start -->
@ -35,10 +40,18 @@
<!-- log end -->
<!-- spring begin -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
@ -70,6 +83,11 @@
<artifactId>jedis</artifactId>
<version>${jedis.version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
<!-- database end -->
<!-- log begin -->

View File

@ -0,0 +1,22 @@
package io.github.dunwu.javadb;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Zhang Peng
* @date 2018/6/19
*/
public class RedissonStandaloneTest {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:redisson-standalone.xml");
RedissonClient redisson = (RedissonClient) applicationContext.getBean("standalone");
// 首先获取redis中的key-value对象key不存在没关系
RBucket<String> keyObject = redisson.getBucket("key");
// 如果key存在就设置key的值为新值value
// 如果key不存在就设置key的值为value
keyObject.set("value");
}
}

View File

@ -0,0 +1,21 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:redisson="http://redisson.org/schema/redisson"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://redisson.org/schema/redisson
http://redisson.org/schema/redisson/redisson.xsd">
<bean id="stringCodec" class="org.redisson.client.codec.StringCodec"/>
<redisson:client id="standalone"
name="aliasName1,aliasName2"
codec-ref="stringCodec">
<redisson:single-server address="redis://127.0.0.1:6379"
connection-pool-size="500"
idle-connection-timeout="10000"
connect-timeout="10000"
timeout="3000"
ping-timeout="30000"
reconnection-timeout="30000"
database="0"/>
</redisson:client>
</beans>