当前位置: 首页>>代码示例>>Java>>正文


Java RedisOperations类代码示例

本文整理汇总了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);
		}
	});
}
 
开发者ID:penggle,项目名称:xproject,代码行数:17,代码来源:RedisCache.java

示例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"));
}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:21,代码来源:TransactionTests.java

示例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;
}
 
开发者ID:trustedanalytics,项目名称:data-acquisition,代码行数:17,代码来源:CloudStoreConfig.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:18,代码来源:RedisHttpSessionConfigurationTests.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:17,代码来源:RedisHttpSessionConfigurationTests.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:18,代码来源:RedisHttpSessionConfigurationTests.java

示例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);
}
 
开发者ID:spring-projects,项目名称:spring-session,代码行数:17,代码来源:RedisHttpSessionConfigurationTests.java

示例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());
    }
}
 
开发者ID:Fourwenwen,项目名称:Breakpoint-http,代码行数:20,代码来源:AppTest.java

示例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);
		}
	});
}
 
开发者ID:penggle,项目名称:xproject,代码行数:13,代码来源:RedisCache.java

示例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;
}
 
开发者ID:ziwenxie,项目名称:leafer,代码行数:8,代码来源:CustomizedRedisCache.java

示例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;
}
 
开发者ID:profullstack,项目名称:spring-seed,代码行数:9,代码来源:ExpirableRedisCache.java

示例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);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:15,代码来源:RedisStringIdempotentRepositoryTest.java

示例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);
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:9,代码来源:StorageConfig.java

示例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));
}
 
开发者ID:trustedanalytics,项目名称:user-management,代码行数:8,代码来源:StorageConfig.java


注:本文中的org.springframework.data.redis.core.RedisOperations类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。