ritesh
ritesh

Reputation: 917

StringRedisTemplate vs StringRedisConnection

  1. What are the differences between StringRedisTemplate and StringRedisConnection[Interface]. [we can use StringRedisConnection by DefaultStringRedisConnection]
  2. What are the different use cases of these two classes.[StringRedisTemplate & DefaultStringRedisConnection]
  3. If there are major differences between two then please tell me merit and demerit of both classes and which class would be better.
  4. Do any of the classes is providing better exception handling?

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

Answers (1)

ebell
ebell

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

Related Questions