Specify which logical database to use with spring-data-redis - spring-boot

I'm using spring-data-redis, spring-session and Spring Boot to connect to my Redis instance. However I would like spring-data-redis to connect not to DB 0 (which is default) but to another local database (say DB 1). This is where I'd like the sessions to be stored. Is this possible with spring-data-redis?

The ConnectionFactory used by RedisTemplate offers configuration options for setting a default DB. Depending on the Redis driver in use both JedisConnectionFactory as well as LettuceConnectionFactory offer void setDatabase(int index).
Using Spring Boot RedisProperties allows to set the default DB via setDatabase or by providing spring.redis.database.

Related

Is it possible to disable a Spring Boot datasource configuration based on unavailability of a connection to a DB

We have an application that uses several data sources. A DB underlying one of those data sources is down at the moment: IOError. Network adapter couldn't establish the connection & Socket read timed out.
Is there an annotation (or other means) of configuring Spring Boot such that it bypasses the culprit data source and still starts up: the DB is not essential in current development work. spring.datasource.continue-on-error=true doesn't seem to work. This is Spring 2.2.2.RELEASE.
using multiple datasource, so when your apps fail at start up your apps still work, i mean using memory db / sqlite to handle fail at connection error...

How to use Spring transactions with plain old jdbc connection without Spring jdbc template?

We have an old EJB based web application which we are supposed to migrate into Spring boot. For database connectivity, it is a plain old jdbc connection approach as of now.
We want to use Spring transactions and remove EJB transactions but willing to keep plain old jdbc connectivity same. In short we don't want to make changes in our DAO layer to convert plain old jdbc to Spring JdbcTemplate.
Please note that we have our own connection pooling algorithm and we create connection object and close it in the pool.
Along with this we want our application to be multi-tenant that can work with multiple databases on the basis of 'tenantID' that we will provide.
I actually tried to implement this but it is not working. I had to manually do con.commit(); and con.rollback();
Is there any way to use Spring transactions with plain old jdbc connectivity with above scenario?

How to configure Couchbase connection pool

I want to configure my connection pool size for Spring Boot Couchbase application, but I can't find any property in order to set it.
A colleague suggested to use (in order to configure queryservice pool)
spring.couchbase.env.endpoints.queryservice.min-endpoints=1
spring.couchbase.env.endpoints.queryservice.max-endpoints=5
but when i do a netstat it doesn't work. i have 1 socket per node.
I am using spring boot.

Using Spring Cloud Connector for Heroku in order to connect to multiple RedisLabs databases

I have a requirement for multiple RedisLabs databases for my application as described in their home page:
multiple dedicated databases in a plan
We enable multiple DBs in a single plan, each running in a dedicated process and in a non-blocking manner.
I rely on Spring Cloud Connectors in order to connect to Heroku (or Foreman in local) and it seems the RedisServiceInfoCreator class allows for a single RedisLabs URL i.e. REDISCLOUD_URL
Here is how I have configured my first redis connection factory:
#Configuration
#Profile({Profiles.CLOUD, Profiles.DEFAULT})
public class RedisCloudConfiguration extends AbstractCloudConfig {
#Bean
public RedisConnectionFactory redisConnectionFactory() {
PoolConfig poolConfig = ...
return connectionFactory().redisConnectionFactory("REDISCLOUD", new PooledServiceConnectorConfig(poolConfig));
}
...
How I am supposed to configure a second connection factory if I intend to use several redis labs databases?
Redis Cloud will set for you an env var only for the first resource in each add-on that you create.
If you create multiple resources in an add-on, you should either set an env var yourself, or use the new endpoint directly in your code.
In short the answer is yes, RedisConnectionFactory should be using Jedis in order to connect to your redis db. it is using jedis pool that can only work with a single redis endpoint. in this regard there is no different between RedisLabs and a basic redis.
you should create several connection pools to work with several redis dbs/endpoints.
just to extend, if you are using multiple dbs to scale, there is no need with RedisLabs as they support clustering with a single endpoint. so you can simple create a single db with as much memory as needed, RedisLabs will create a cluster for you and will scale your redis automatically.
if you app does require logical seperation, then creation multiple dbs is the right way to go.

MongoDB in spring web project

I am writing a web project in spring 3.1.0, and I am using mongodb 1.0.0.RELEASE.
I need to get the MongoTemplate object into the controller without opening unnecessary new connections, something like a pool? How can I do this?
Thanks
MongoTemplate uses MongoDB java driver which does connection pooling. You could optionally configure the number of connections, timeouts, etc.

Resources