<bean id="redisConnectionFactory" class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory"> <property name="hostName" value="localhost"/> <property name="port" value="6379"/> </bean> <bean id="redisTemplate" class="org.springframework.data.redis.core.RedisTemplate"> <property name="connectionFactory" ref="redisConnectionFactory"/> <property name="defaultSerializer" ref="stringRedisSerializer"/> <property name="hashKeySerializer" ref="stringRedisSerializer"/> <property name="hashValueSerializer" ref="jdkSerializationRedisSerializer"/> <property name="valueSerializer" ref="jdkSerializationRedisSerializer"/> </bean> @Transactional public void performTransactions() { redisTemplate.execute(new SessionCallback<Object>() { @Override public Object execute(RedisOperations operations) throws DataAccessException { operations.opsForValue().set("key1", "value1"); operations.opsForValue().set("key2", "value2"); return null; } }); }


上一篇:
下一篇:
切换中文