<dependencies>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-redis</artifactId>
<version>1.8.1.RELEASE</version>
</dependency>
</dependencies>
<bean id="jedisConnFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory" p:use-pool="true"/> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate" p:connection-factory-ref="jedisConnFactory"/>
opsForValue() - Operations for working with entries having simple values opsForList() - Operations for working with entries having list values opsForSet() - Operations for working with entries having set values opsForZSet() - Operations for working with entries having ZSet (sorted set) values opsForHash() - Operations for working with entries having hash values boundValueOps(K) - Operations for working with simple values bound to a given key boundListOps(K) - Operations for working with list values bound to a given key boundSetOps(K) - Operations for working with set values bound to a given key boundZSet(K) - Operations for working with ZSet (sorted set) values bound to a given key boundHashOps(K) - Operations for working with hash values bound to a given key
public class Example {
// inject the actual template
@Autowired
private RedisTemplate<String, String> template;
// inject the template as ListOperations
// can also inject as Value, Set, ZSet, and HashOperations
@Resource(name="redisTemplate")
private ListOperations<String, String> listOps;
public void addLink(String userId, URL url) {
listOps.leftPush(userId, url.toExternalForm());
// or use template directly
template.boundListOps(userId).leftPush(url.toExternalForm());
}
}
BoundListOperations<String, Product> mangoOps = redis.boundListOps("solidmango");
Product popped = mangoOps.rightPop();
mangoOps.rightPush(product1);
mangoOps.rightPush(product2);
mangoOps.rightPush(product3);
@Bean
public RedisTemplate<String, Cart> redisTemplate(RedisConnectionFactory rcf) {
RedisTemplate<String, Cart> redis =
new RedisTemplate<String, Cart>();
redis.setConnectionFactory(rcf);
redis.setKeySerializer(new StringRedisSerializer());
redis.setValueSerializer(
new Jackson2JsonRedisSerializer<Product>(Product.class));
return redis;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有