2013-03-10 49 views

回答

2

序列化器用於代碼庫中的一些地方,最顯着的是在RedisTemplate中將存儲在Redis中的原始字節作爲鍵/值轉換爲您的自定義數據類型(反之亦然)。這在文檔的第4.4節中提到。

0

在你Spring配置

<bean id="stringSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/> 

<bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" 
    p:connection-factory-ref="jedisConnectionFactory"> 
    <property name="keySerializer" ref="stringSerializer"/> 
    <property name="valueSerializer" ref="stringSerializer"/> 
</bean> 

<bean id="jedisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" 
    p:host-name="myhostname" p:port="6379"/> 

或者,如果你想將其設置爲的Java

// inject the actual template 
     @Autowired 
     private RedisTemplate<String, Object> template; 
... 
... 
template.setKeySerializer(new StringRedisSerializer()); 
template.setValueSerializer(new StringRedisSerializer()); 
相關問題