Java 类org.springframework.data.redis.core.RedisOperations 实例源码

项目:Breakpoint-http    文件:AppTest.java   
@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());
    }
}
项目:xproject    文件:RedisCache.java   
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);
        }
    });
}
项目:jaf-examples    文件:TransactionTests.java   
@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"));
}
项目:data-acquisition    文件:CloudStoreConfig.java   
@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;
}
项目:spring-session    文件:RedisHttpSessionConfigurationTests.java   
@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);
}
项目:spring-session    文件:RedisHttpSessionConfigurationTests.java   
@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);
}
项目:spring-session    文件:RedisHttpSessionConfigurationTests.java   
@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);
}
项目:spring-session    文件:RedisHttpSessionConfigurationTests.java   
@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);
}
项目:xproject    文件:RedisCache.java   
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);
        }
    });
}
项目:leafer    文件:CustomizedRedisCache.java   
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;
}
项目:leafer    文件:CustomizedRedisCache.java   
public CustomizedRedisCache(String name, byte[] prefix,
        RedisOperations<? extends Object, ? extends Object> redisOperations,
        long expiration,long preloadSecondTime, boolean allowNullValues) {
    super(name, prefix, redisOperations, expiration, allowNullValues);
    this.redisOperations = redisOperations;
    this.preloadSecondTime = preloadSecondTime;
}
项目:spring-seed    文件:ExpirableRedisCache.java   
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;
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisAutoConfigurationTests.java   
@Test
public void testDefaultRedisConfiguration() throws Exception {
    load();
    assertThat(this.context.getBean("redisTemplate", RedisOperations.class))
            .isNotNull();
    assertThat(this.context.getBean(StringRedisTemplate.class)).isNotNull();
}
项目:spring-boot-concourse    文件:RedisAutoConfigurationTests.java   
@Test
public void testDefaultRedisConfiguration() throws Exception {
    load();
    assertThat(this.context.getBean("redisTemplate", RedisOperations.class))
            .isNotNull();
    assertThat(this.context.getBean(StringRedisTemplate.class)).isNotNull();
}
项目:Camel    文件:RedisStringIdempotentRepositoryTest.java   
@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);
}
项目:user-management    文件:StorageConfig.java   
@Bean
public RedisOperations<String, SecurityCode> redisTemplate(RedisConnectionFactory redisConnectionFactory,
                                                           HashedStringRedisSerializer hashedStringRedisSerializer,
                                                           SecureJacksonJsonRedisSerializer<SecurityCode> secureJacksonJsonRedisSerializer) {
    return CommonConfiguration.redisTemplate(redisConnectionFactory,
            hashedStringRedisSerializer,
            secureJacksonJsonRedisSerializer);
}
项目:user-management    文件:StorageConfig.java   
@Bean
public RedisOperations<String, AccessInvitations> redisAccessInvitationsTemplate(RedisConnectionFactory redisConnectionFactory,
                                                                                 HashedStringRedisSerializer hashedStringRedisSerializer) {
    return CommonConfiguration.redisTemplate(redisConnectionFactory,
            hashedStringRedisSerializer,
            new JacksonJsonRedisSerializer<AccessInvitations>(AccessInvitations.class));
}
项目:user-management    文件:StorageConfig.java   
private static <T> RedisOperations<String, T> redisTemplate(RedisConnectionFactory redisConnectionFactory,
                                                            RedisSerializer<String> keySerializer,
                                                            RedisSerializer<T> valueSerializer) {
    RedisTemplate<String, T> template = new RedisTemplate<String, T>();
    template.setConnectionFactory(redisConnectionFactory);

    RedisSerializer<String> stringSerializer = new StringRedisSerializer();
    template.setKeySerializer(stringSerializer);
    template.setValueSerializer(valueSerializer);
    template.setHashKeySerializer(keySerializer);
    template.setHashValueSerializer(valueSerializer);

    return template;
}
项目:onetwo    文件:UpdatableRedisCache.java   
public UpdatableRedisCache(
            String name,
            byte[] prefix,
            RedisOperations<? extends Object, ? extends Object> redisOperations,
            long expiration) {
        super(name, prefix, redisOperations, expiration);
        this.redisOperations = redisOperations;
//      self = PropertyAccessorFactory.forDirectFieldAccess(this);
        this.expirationInSeconds = expiration;
    }
项目:spring-session    文件:RedisOperationsSessionRepository.java   
/**
 * Creates a new instance. For an example, refer to the class level javadoc.
 *
 * @param sessionRedisOperations The {@link RedisOperations} to use for managing the
 * sessions. Cannot be null.
 */
public RedisOperationsSessionRepository(
        RedisOperations<Object, Object> sessionRedisOperations) {
    Assert.notNull(sessionRedisOperations, "sessionRedisOperations cannot be null");
    this.sessionRedisOperations = sessionRedisOperations;
    this.expirationPolicy = new RedisSessionExpirationPolicy(sessionRedisOperations,
            this::getExpirationsKey, this::getSessionKey);
}
项目:spring-session    文件:RedisSessionExpirationPolicy.java   
RedisSessionExpirationPolicy(RedisOperations<Object, Object> sessionRedisOperations,
        Function<Long, String> lookupExpirationKey, Function<String, String> lookupSessionKey) {
    super();
    this.redis = sessionRedisOperations;
    this.lookupExpirationKey = lookupExpirationKey;
    this.lookupSessionKey = lookupSessionKey;
}
项目:parrot-rest    文件:HashOperationsMock.java   
@Override
public RedisOperations<String, ?> getOperations() {
    throw new UnsupportedOperationException("Unsupported method");
}
项目:busi-support    文件:CustomerRedisCacheManager.java   
public CustomerRedisCacheManager(RedisOperations redisOperations) {
    super(redisOperations);
}
项目:leafer    文件:CustomizedRedisCacheManager.java   
public CustomizedRedisCacheManager(RedisOperations redisOperations) {
    super(redisOperations);
}
项目:leafer    文件:CustomizedRedisCacheManager.java   
public CustomizedRedisCacheManager(RedisOperations redisOperations, Collection<String> cacheNames) {
    super(redisOperations, cacheNames);
}
项目:springbootWeb    文件:CustomerRedisCacheManager.java   
public CustomerRedisCacheManager(RedisOperations redisOperations) {
    super(redisOperations);
}
项目:spring-seed    文件:ExpirableRedisCacheManager.java   
public ExpirableRedisCacheManager(RedisOperations redisOperations) {
    super(redisOperations);
}
项目:spring-seed    文件:ExpirableRedisCacheManager.java   
@SuppressWarnings("rawtypes")
public ExpirableRedisCacheManager(RedisOperations redisOperations, Collection<String> cacheNames) {
    super(redisOperations, cacheNames);
}
项目:jaf-examples    文件:TransactionTests.java   
@Test
public void testWatch() throws InterruptedException {
    final String watchKey = "watchKey";

    redisTemplate.opsForValue().set(watchKey, "value0");

    Thread t1 = new Thread(new Runnable() {
        @Override
        public void run() {
            List<Object> result = redisTemplate.execute(new SessionCallback<List<Object>>() {
                @SuppressWarnings({ "rawtypes", "unchecked" })
                @Override
                public List<Object> execute(RedisOperations operations) throws DataAccessException {
                    operations.watch(watchKey);  // watch

                    String oldValue = (String) operations.opsForValue().get(watchKey);
                    String newValue = oldValue + "-11";

                    operations.multi();  // 开启事物
                    operations.opsForValue().set(watchKey, newValue);  // 修改值

                    try {
                        Thread.sleep(1000);  // 让子线程暂停下,以便其他线程修改 watchKey 的值
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    return operations.exec();  // 提交事物
                }
            });

            assertThat(result).isNull();  // 事物提交失败,返回null,否则会返回一个空 List
        }
    });
    t1.start();

    Thread.sleep(100);
    redisTemplate.opsForValue().set(watchKey, "value2");  // 主线程先修改 watchKey 的值,子线程提交时会观察到 watchKey 的值已经改变,所以子线程事物提交会失败
    t1.join();

    assertThat(redisTemplate.opsForValue().get(watchKey)).isEqualTo("value2");
}
项目:todolist    文件:AppCacheManager.java   
public AppCacheManager(RedisOperations redisOperations) {
    super(redisOperations);
    this.ops = redisOperations;
    this.setUsePrefix(true);
}
项目:todolist    文件:AppCacheManager.java   
public AppCacheManager(RedisOperations redisOperations, Collection<String> cacheNames) {
    super(redisOperations, cacheNames);
    this.ops = redisOperations;
    this.setUsePrefix(true);
}
项目:redis-admin    文件:DefaultBoundSetOperations.java   
public RedisOperations<K, V> getOperations() {
    return ops.getOperations();
}
项目:redis-admin    文件:DefaultBoundKeyOperations.java   
public DefaultBoundKeyOperations(K key, RedisOperations<K, ?> operations) {
    setKey(key);
    this.ops = operations;
}
项目:redis-admin    文件:DefaultBoundValueOperations.java   
public RedisOperations<K, V> getOperations() {
    return ops.getOperations();
}
项目:redis-admin    文件:AbstractOperations.java   
public RedisOperations<K, V> getOperations() {
    return template;
}
项目:redis-admin    文件:DefaultBoundHashOperations.java   
public RedisOperations<H, ?> getOperations() {
    return ops.getOperations();
}
项目:redis-admin    文件:DefaultBoundListOperations.java   
public RedisOperations<K, V> getOperations() {
    return ops.getOperations();
}
项目:redis-admin    文件:DefaultBoundZSetOperations.java   
public RedisOperations<K, V> getOperations() {
    return ops.getOperations();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:RedisUtils.java   
static RedisOperations<String, String> stringTemplate(
        RedisConnectionFactory redisConnectionFactory) {
    return new StringRedisTemplate(redisConnectionFactory);
}
项目:easycode    文件:CustomRedisCacheManager.java   
public CustomRedisCacheManager(RedisOperations redisOperations) {
    super(redisOperations);
}