本文整理汇总了Java中org.springframework.data.redis.core.RedisOperations类的典型用法代码示例。如果您正苦于以下问题:Java RedisOperations类的具体用法?Java RedisOperations怎么用?Java RedisOperations使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RedisOperations类属于org.springframework.data.redis.core包,在下文中一共展示了RedisOperations类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: put
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
public Object put(final String key, final Object value) throws CacheException {
final String realKey = key(key);
return redisTemplate.execute(new SessionCallback<Object>(){
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();//事务开启
operations.opsForValue().get(realKey);
if(cacheExpire){
operations.opsForValue().set(realKey, value, cacheExpireSeconds, TimeUnit.SECONDS);
}else{
operations.opsForValue().set(realKey, value);
}
List<Object> results = operations.exec(); //结束事务
return results.get(0);
}
});
}
示例2: testUseTransactionSimple
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void testUseTransactionSimple() {
redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public List<Object> execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.opsForValue().set("test1", "value1");
operations.opsForSet().add("testSet1", "value1", "value2");
// 这里获取 test1 为 null,因为事务还没有提交
assertThat(operations.opsForValue().get("test1")).isNull();
return operations.exec();
}
});
assertThat(redisTemplate.opsForValue().get("test1")).isEqualTo("value1");
MatcherAssert.assertThat(redisTemplate.opsForSet().members("testSet1"), Matchers.containsInAnyOrder("value1", "value2"));
}
示例3: redisTemplate
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Bean
public RedisOperations<String, Request> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
RedisTemplate<String, Request> template = new RedisTemplate<String, Request>();
template.setConnectionFactory(redisConnectionFactory);
RedisSerializer<String> keySerializer = new StringRedisSerializer();
Jackson2JsonRedisSerializer<Request> requestSerializer = new Jackson2JsonRedisSerializer<Request>(Request.class);
template.setKeySerializer(keySerializer);
template.setValueSerializer(requestSerializer);
template.setHashKeySerializer(keySerializer);
template.setHashValueSerializer(requestSerializer);
return template;
}
示例4: qualifiedConnectionFactoryRedisConfig
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void qualifiedConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class,
QualifiedConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context
.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context
.getBean("qualifiedRedisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils
.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
.isEqualTo(redisConnectionFactory);
}
示例5: primaryConnectionFactoryRedisConfig
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void primaryConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class, PrimaryConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context
.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context
.getBean("primaryRedisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils
.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
.isEqualTo(redisConnectionFactory);
}
示例6: qualifiedAndPrimaryConnectionFactoryRedisConfig
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void qualifiedAndPrimaryConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class,
QualifiedAndPrimaryConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context
.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context
.getBean("qualifiedRedisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils
.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
.isEqualTo(redisConnectionFactory);
}
示例7: namedConnectionFactoryRedisConfig
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void namedConnectionFactoryRedisConfig() {
registerAndRefresh(RedisConfig.class, NamedConnectionFactoryRedisConfig.class);
RedisOperationsSessionRepository repository = this.context
.getBean(RedisOperationsSessionRepository.class);
RedisConnectionFactory redisConnectionFactory = this.context
.getBean("redisConnectionFactory", RedisConnectionFactory.class);
assertThat(repository).isNotNull();
assertThat(redisConnectionFactory).isNotNull();
RedisOperations redisOperations = (RedisOperations) ReflectionTestUtils
.getField(repository, "sessionRedisOperations");
assertThat(redisOperations).isNotNull();
assertThat(ReflectionTestUtils.getField(redisOperations, "connectionFactory"))
.isEqualTo(redisConnectionFactory);
}
示例8: testRedisMap
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void testRedisMap() {
Object object = redisTemplate.execute(new SessionCallback() {
@Override
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();
operations.opsForValue().get("test");
operations.delete("test");
operations.opsForValue().set("test", "6");
List<String> rs = operations.exec();
System.out.println(" rs:" + rs.toString());
return rs;
}
});
List<Object> strings = (List<Object>) object;
for (Object str : strings) {
System.err.println(str.toString());
}
}
示例9: remove
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
public Object remove(final String key) throws CacheException {
final String realKey = key(key);
return redisTemplate.execute(new SessionCallback<Object>(){
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();//事务开启
operations.opsForValue().get(realKey);
operations.delete(realKey);
List<Object> results = operations.exec(); //结束事务
return results.get(0);
}
});
}
示例10: CustomizedRedisCache
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
public CustomizedRedisCache(String name, byte[] prefix,
RedisOperations<? extends Object, ? extends Object> redisOperations,
long expiration,long preloadSecondTime) {
super(name, prefix, redisOperations, expiration);
this.redisOperations = redisOperations;
this.preloadSecondTime = preloadSecondTime;
}
示例11: ExpirableRedisCache
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
public ExpirableRedisCache(String name, byte[] prefix, RedisOperations<? extends Object, ? extends Object> redisOperations, long expiration) {
super(name, prefix, redisOperations, expiration);
this.cacheMetadata = new ExpirableRedisCacheMetadata(name, prefix);
this.cacheMetadata.setDefaultExpiration(expiration);
this.redisOperations = redisOperations;
}
示例12: testDefaultRedisConfiguration
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Test
public void testDefaultRedisConfiguration() throws Exception {
load();
assertThat(this.context.getBean("redisTemplate", RedisOperations.class))
.isNotNull();
assertThat(this.context.getBean(StringRedisTemplate.class)).isNotNull();
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:8,代码来源:RedisAutoConfigurationTests.java
示例13: setUp
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
redisTemplate = mock(RedisTemplate.class);
valueOperations = mock(ValueOperations.class);
redisConnection = mock(RedisConnection.class);
redisOperations = mock(RedisOperations.class);
redisConnectionFactory = mock(RedisConnectionFactory.class);
when(redisTemplate.opsForValue()).thenReturn(valueOperations);
when(redisTemplate.getConnectionFactory()).thenReturn(redisConnectionFactory);
when(valueOperations.getOperations()).thenReturn(redisOperations);
when(redisTemplate.getConnectionFactory().getConnection()).thenReturn(redisConnection);
idempotentRepository = new RedisStringIdempotentRepository(redisTemplate, REPOSITORY);
idempotentRepository.setExpiry(1000L);
}
示例14: redisTemplate
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Bean
public RedisOperations<String, SecurityCode> redisTemplate(RedisConnectionFactory redisConnectionFactory,
HashedStringRedisSerializer hashedStringRedisSerializer,
SecureJacksonJsonRedisSerializer<SecurityCode> secureJacksonJsonRedisSerializer) {
return CommonConfiguration.redisTemplate(redisConnectionFactory,
hashedStringRedisSerializer,
secureJacksonJsonRedisSerializer);
}
示例15: redisAccessInvitationsTemplate
import org.springframework.data.redis.core.RedisOperations; //导入依赖的package包/类
@Bean
public RedisOperations<String, AccessInvitations> redisAccessInvitationsTemplate(RedisConnectionFactory redisConnectionFactory,
HashedStringRedisSerializer hashedStringRedisSerializer) {
return CommonConfiguration.redisTemplate(redisConnectionFactory,
hashedStringRedisSerializer,
new JacksonJsonRedisSerializer<AccessInvitations>(AccessInvitations.class));
}