當前位置: 首頁>>代碼示例>>Java>>正文


Java RedisSerializer類代碼示例

本文整理匯總了Java中org.springframework.data.redis.serializer.RedisSerializer的典型用法代碼示例。如果您正苦於以下問題:Java RedisSerializer類的具體用法?Java RedisSerializer怎麽用?Java RedisSerializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RedisSerializer類屬於org.springframework.data.redis.serializer包,在下文中一共展示了RedisSerializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: redisTemplate

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Bean(name="redisTemplate")
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory factory) {

    RedisTemplate<String, String> template = new RedisTemplate<>();


    RedisSerializer<String> redisSerializer = new StringRedisSerializer();

    Jackson2JsonRedisSerializer jackson2JsonRedisSerializer = new Jackson2JsonRedisSerializer(Object.class);
    ObjectMapper om = new ObjectMapper();
    om.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.ANY);
    om.enableDefaultTyping(ObjectMapper.DefaultTyping.NON_FINAL);
    jackson2JsonRedisSerializer.setObjectMapper(om);

    template.setConnectionFactory(factory);
    //key序列化方式
    template.setKeySerializer(redisSerializer);
    //value序列化
    template.setValueSerializer(jackson2JsonRedisSerializer);
    //value hashmap序列化
    template.setHashValueSerializer(jackson2JsonRedisSerializer);

    return template;
}
 
開發者ID:cwenao,項目名稱:springboot_cwenao,代碼行數:25,代碼來源:RedisConfig.java

示例2: redisTemplate

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Bean
@Primary
RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory rcf) {
	AitLogger.debug(logger, "Serializer overriding ");

	RedisTemplate<String, Object> template = new RedisTemplate<>();
	template.setConnectionFactory(rcf);

	GenericJackson2JsonRedisSerializer valSerializer = new GenericJackson2JsonRedisSerializer();

	template.setValueSerializer(valSerializer);
	template.setKeySerializer(new RedisSerializer<Object>() {

		@Override
		public byte[] serialize(Object t) throws SerializationException {
			return (t == null ? null : (":" + t.toString()).getBytes());
		}

		@Override
		public Object deserialize(byte[] bytes) throws SerializationException {
			return (bytes == null ? null : new String(bytes));
		}
	});
	template.setHashValueSerializer(valSerializer);
	return template;
}
 
開發者ID:allianzit,項目名稱:ait-platform,代碼行數:27,代碼來源:AitCacheConfigBase.java

示例3: updatetag

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
@SuppressWarnings({"rawtypes", "unchecked"})
public Integer updatetag(Integer tId) {
    //標簽
    List<Tag> tags = tagMapper.getAllTags();
    JsonArray jsonArray = new JsonArray();
    for (Tag tag : tags) {
        List<Blog> blogs = tagMapper.getblogbytagid(tag.gettId());
        String str = tag.gettName() + " " + "(" + String.valueOf(blogs.size()) + ")";
        KeyAndValue keyAndValue = new KeyAndValue();
        keyAndValue.setKey(tag.gettName());
        keyAndValue.setValue(str);
        JsonObject jsonObject = new JsonObject();
        jsonObject.addProperty("key", tag.gettId());
        jsonObject.addProperty("value", str);
        jsonArray.add(jsonObject);
    }
    boolean result = redisTemplate.execute((RedisCallback<Boolean>) connection -> {
        RedisSerializer<String> serializer = redisTemplate.getStringSerializer();
        connection.set(serializer.serialize("biaoqian"), serializer.serialize(jsonArray.toString()));
        return true;
    });
    return tId;
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:25,代碼來源:TagServiceImpl.java

示例4: getKeysValues

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
/**
 * 根據key獲取對象
 *
 * @param keyPatten the key patten
 * @return the keys values
 */
public Map<String, String> getKeysValues(final String keyPatten) {
    LOGGER.info("[redisTemplate redis]  getValues()  patten={} ", keyPatten);
    return redisTemplate.execute((RedisCallback<Map<String, String>>) connection -> {
        RedisSerializer<String> serializer = getRedisSerializer();
        Map<String, String> maps = new HashMap<>();
        Set<String> keys = redisTemplate.keys(keyPatten + "*");
        for (String key : keys) {
            byte[] bKeys = serializer.serialize(key);
            byte[] bValues = connection.get(bKeys);
            String value = serializer.deserialize(bValues);
            maps.put(key, value);
        }
        return maps;
    });
}
 
開發者ID:ruyangit,項目名稱:angit,代碼行數:22,代碼來源:RedisRepository.java

示例5: getObject

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
public Object getObject(Object key)
{
    Object result = null;
    JedisConnection connection = null;
    try
    {
        connection = jedisConnectionFactory.getConnection();
        RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
        result = serializer.deserialize(connection.get(serializer.serialize(key)));
    }
    catch (JedisConnectionException e)
    {
        e.printStackTrace();
    }
    finally
    {
        if (connection != null) {
            connection.close();
        }
    }
    return result;
}
 
開發者ID:mazhaoyong,項目名稱:api-server-seed,代碼行數:24,代碼來源:RedisCache.java

示例6: putObject

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
public void putObject(Object key, Object value)
{
    JedisConnection connection = null;
    try
    {
        connection = jedisConnectionFactory.getConnection();
        RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
        connection.set(serializer.serialize(key), serializer.serialize(value));
    }
    catch (JedisConnectionException e)
    {
        e.printStackTrace();
    }
    finally
    {
        if (connection != null) {
            connection.close();
        }
    }
}
 
開發者ID:mazhaoyong,項目名稱:api-server-seed,代碼行數:22,代碼來源:RedisCache.java

示例7: removeObject

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
public Object removeObject(Object key)
{
    JedisConnection connection = null;
    Object result = null;
    try
    {
        connection = jedisConnectionFactory.getConnection();
        RedisSerializer<Object> serializer = new JdkSerializationRedisSerializer();
        result =connection.expire(serializer.serialize(key), 0);
    }
    catch (JedisConnectionException e)
    {
        e.printStackTrace();
    }
    finally
    {
        if (connection != null) {
            connection.close();
        }
    }
    return result;
}
 
開發者ID:mazhaoyong,項目名稱:api-server-seed,代碼行數:24,代碼來源:RedisCache.java

示例8: stringReactiveRedisTemplate

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Bean
//TODO: replace with ReactiveStringRedisTemplate in future
public ReactiveRedisTemplate<String, String> stringReactiveRedisTemplate(
		ReactiveRedisConnectionFactory reactiveRedisConnectionFactory,
		ResourceLoader resourceLoader) {
	RedisSerializer<String> serializer = new StringRedisSerializer();
	RedisSerializationContext<String , String> serializationContext = RedisSerializationContext
			.<String, String>newSerializationContext()
			.key(serializer)
			.value(serializer)
			.hashKey(serializer)
			.hashValue(serializer)
			.build();
	return new ReactiveRedisTemplate<>(reactiveRedisConnectionFactory,
			serializationContext);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-gateway,代碼行數:17,代碼來源:GatewayRedisAutoConfiguration.java

示例9: update

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
public boolean update(final String key, final String value) {
    if (get(key) == null) {
        throw new NullPointerException("數據行不存在, key = " + key);
    }
    boolean result = redisTemplate.execute(new RedisCallback<Boolean>() {
        public Boolean doInRedis(RedisConnection connection)
                throws DataAccessException {
            RedisSerializer<String> serializer = getRedisSerializer();
            byte[] keyStr = serializer.serialize(key);
            byte[] valueStr = serializer.serialize(value);
            connection.set(keyStr, valueStr);
            return true;
        }
    });
    return result;
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:18,代碼來源:RedisDaoImpl.java

示例10: get

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
public <T> T get(final String key, final Class clazz) {
    T result = redisTemplate.execute(new RedisCallback<T>() {
        public T doInRedis(RedisConnection connection)
                throws DataAccessException {
            RedisSerializer<String> serializer = getRedisSerializer();
            byte[] keyStr = serializer.serialize(key);
            byte[] value = connection.get(keyStr);
            if (value == null) {
                return null;
            }
            String valueStr = serializer.deserialize(value);
            return (T) JSON.parseObject(valueStr, clazz);
        }
    });
    return result;
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:18,代碼來源:RedisDaoImpl.java

示例11: getList

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Override
public <T> List<T> getList(final String key, final Class<T> clazz) {
    List<T> result = redisTemplate.execute(new RedisCallback<List<T>>() {
        public List<T> doInRedis(RedisConnection connection)
                throws DataAccessException {
            RedisSerializer<String> serializer = getRedisSerializer();
            byte[] keyStr = serializer.serialize(key);
            byte[] value = connection.get(keyStr);
            if (value == null) {
                return null;
            }
            String valueStr = serializer.deserialize(value);
            return JSON.parseArray(valueStr, clazz);
        }
    });
    return result;
}
 
開發者ID:bill1012,項目名稱:AdminEAP,代碼行數:18,代碼來源:RedisDaoImpl.java

示例12: redisTemplate

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的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

示例13: redisTemplate

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Bean
public RedisTemplate<String, Album> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
    RedisTemplate<String, Album> template = new RedisTemplate<String, Album>();

    template.setConnectionFactory(redisConnectionFactory);

    RedisSerializer<String> stringSerializer = new StringRedisSerializer();
    RedisSerializer<Album> albumSerializer = new JacksonJsonRedisSerializer<Album>(Album.class);

    template.setKeySerializer(stringSerializer);
    template.setValueSerializer(albumSerializer);
    template.setHashKeySerializer(stringSerializer);
    template.setHashValueSerializer(albumSerializer);

    return template;
}
 
開發者ID:pivotalservices,項目名稱:concourse-spring-music,代碼行數:17,代碼來源:RedisConfig.java

示例14: DefaultPersistenceService

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Autowired
public DefaultPersistenceService(@Qualifier("orderingTemplate") @NonNull final StringRedisTemplate orderingTemplate,
                                 @Qualifier("valueTemplate") @NonNull final RedisTemplate<String, EmailSchedulingData> valueTemplate) {
    this.orderingTemplate = orderingTemplate;
    this.orderingTemplate.setEnableTransactionSupport(true);

    this.valueTemplate = valueTemplate;
    RedisSerializer<String> stringSerializer = new StringRedisSerializer();
    JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
    this.valueTemplate.setKeySerializer(stringSerializer);
    this.valueTemplate.setValueSerializer(jdkSerializationRedisSerializer);
    this.valueTemplate.setHashKeySerializer(stringSerializer);
    this.valueTemplate.setHashValueSerializer(stringSerializer);
    this.valueTemplate.setEnableTransactionSupport(true);
    this.valueTemplate.afterPropertiesSet();
}
 
開發者ID:ozimov,項目名稱:spring-boot-email-tools,代碼行數:17,代碼來源:DefaultPersistenceService.java

示例15: createValueTemplate

import org.springframework.data.redis.serializer.RedisSerializer; //導入依賴的package包/類
@Bean
@Qualifier("valueTemplate")
public RedisTemplate<String, EmailSchedulingData> createValueTemplate() throws IOException {
    RedisTemplate<String, EmailSchedulingData> template = new RedisTemplate<>();
    RedisSerializer<String> stringSerializer = new StringRedisSerializer();
    JdkSerializationRedisSerializer jdkSerializationRedisSerializer = new JdkSerializationRedisSerializer();
    template.setKeySerializer(stringSerializer);
    template.setValueSerializer(jdkSerializationRedisSerializer);
    template.setHashKeySerializer(stringSerializer);
    template.setHashValueSerializer(stringSerializer);

    template.setConnectionFactory(redisConnectionFactory);
    template.setEnableTransactionSupport(true);
    template.afterPropertiesSet();
    return template;
}
 
開發者ID:ozimov,項目名稱:spring-boot-email-tools,代碼行數:17,代碼來源:EmailRedisTemplateConfiguration.java


注:本文中的org.springframework.data.redis.serializer.RedisSerializer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。