Reputation: 917
StringRedisTemplate
and StringRedisConnection
[Interface]. [we can use StringRedisConnection
by DefaultStringRedisConnection
]StringRedisTemplate
& DefaultStringRedisConnection
]It seems to me that both classes are doing same thing. If they are doing same set of operations on redis and one class is just syntactic sugar then why these are introduced as separate classes. I am sure that I might be missing something.
Please do not list method name. StringRedisTemplate, StringRedisConnection
Upvotes: 2
Views: 2555
Reputation: 137
The StringRedisTemplate
gives you access to a Redis connection which in this case will be a DefaultStringRedisConnection
which is an implementation of the StringRedisConnection
.
The StringRedisTemplate
follows the same pattern as JdbcTemplate
, JmsTemplate
, MongoTemplate
etc... Read this link. The key reason to have the Template class is to hide all the boilerplate code from the developer. Thus speeding up development process, reduces the amount of code required and in turn reduce that amount of testing required and bugs. The Template/Connection will handle any exceptions i.e. will transform Redis exceptions into the correct DAO ones.
The RedisTemplate
and StringRedisTemplate
are classes for you to use to help simplify your access code to your Redis data. Also note that once the Template is configured the class is thread safe.
Upvotes: 2