標籤:value 模組 cti 字元 boolean 操作 call work end
Spring Data Redis
對字串的操作,封裝在了ValueOperations
和BoundValueOperations
中,在整合好了SPD之後,在需要的地方引入:
// 注入模板操作執行個體@Autowiredprivate RedisTemplate template;// 從模板中取出對應的操作類執行個體@Resource(name = "redisTemplate")private ValueOperations valueOps;
由於儲存在Redis
中的鍵和值通常是java.lang.String
,因此Redis
模組為RedisConnection
和RedisTemplate
提供了兩個擴充,分別是StringRedisConnection
(及其DefaultStringRedisConnection
實現)和StringRedisTemplate
(相當於RedisTemplate<String, String>
)。
org.springframework.data.redis.core.StringRedisTemplate
源碼如下:
public class StringRedisTemplate extends RedisTemplate<String, String> {/** * Constructs a new <code>StringRedisTemplate</code> instance. {@link #setConnectionFactory(RedisConnectionFactory)} * and {@link #afterPropertiesSet()} still need to be called. */public StringRedisTemplate() { RedisSerializer<String> stringSerializer = new StringRedisSerializer(); setKeySerializer(stringSerializer); setValueSerializer(stringSerializer); setHashKeySerializer(stringSerializer); setHashValueSerializer(stringSerializer);}/** * Constructs a new <code>StringRedisTemplate</code> instance ready to be used. * * @param connectionFactory connection factory for creating new connections */public StringRedisTemplate(RedisConnectionFactory connectionFactory) { this(); setConnectionFactory(connectionFactory); afterPropertiesSet();}protected RedisConnection preProcessConnection(RedisConnection connection, boolean existingConnection) { return new DefaultStringRedisConnection(connection);}}
實際就是繼承自RedisTemplate
Spring Data Redis入門樣本:字串操作(六)