http service: use jedis connection pool
This commit is contained in:
@@ -49,7 +49,8 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
import org.sql2o.Sql2o;
|
import org.sql2o.Sql2o;
|
||||||
import org.sql2o.converters.Converter;
|
import org.sql2o.converters.Converter;
|
||||||
import org.sql2o.quirks.NoQuirks;
|
import org.sql2o.quirks.NoQuirks;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.JedisPool;
|
||||||
|
import redis.clients.jedis.JedisPoolConfig;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
@@ -130,9 +131,9 @@ public class SpringBootWebApplication extends SpringBootServletInitializer
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
Jedis jedis()
|
JedisPool jedis()
|
||||||
{
|
{
|
||||||
return new Jedis(redisHost);
|
return new JedisPool(new JedisPoolConfig(), redisHost);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ import org.sql2o.Connection;
|
|||||||
import org.sql2o.Sql2o;
|
import org.sql2o.Sql2o;
|
||||||
import org.sql2o.Sql2oException;
|
import org.sql2o.Sql2oException;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
|
import redis.clients.jedis.JedisPool;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/account")
|
@RequestMapping("/account")
|
||||||
@@ -97,7 +98,7 @@ public class AccountService
|
|||||||
private final String oauthClientId;
|
private final String oauthClientId;
|
||||||
private final String oauthClientSecret;
|
private final String oauthClientSecret;
|
||||||
private final AuthFilter auth;
|
private final AuthFilter auth;
|
||||||
private final Jedis jedis;
|
private final JedisPool jedisPool;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public AccountService(
|
public AccountService(
|
||||||
@@ -105,14 +106,14 @@ public class AccountService
|
|||||||
@Value("${oauth.client-id}") String oauthClientId,
|
@Value("${oauth.client-id}") String oauthClientId,
|
||||||
@Value("${oauth.client-secret}") String oauthClientSecret,
|
@Value("${oauth.client-secret}") String oauthClientSecret,
|
||||||
AuthFilter auth,
|
AuthFilter auth,
|
||||||
Jedis jedis
|
JedisPool jedisPool
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
this.sql2o = sql2o;
|
this.sql2o = sql2o;
|
||||||
this.oauthClientId = oauthClientId;
|
this.oauthClientId = oauthClientId;
|
||||||
this.oauthClientSecret = oauthClientSecret;
|
this.oauthClientSecret = oauthClientSecret;
|
||||||
this.auth = auth;
|
this.auth = auth;
|
||||||
this.jedis = jedis;
|
this.jedisPool = jedisPool;
|
||||||
|
|
||||||
try (Connection con = sql2o.open())
|
try (Connection con = sql2o.open())
|
||||||
{
|
{
|
||||||
@@ -248,7 +249,10 @@ public class AccountService
|
|||||||
service.send(response);
|
service.send(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
jedis.publish("session." + uuid, websocketGson.toJson(response, WebsocketMessage.class));
|
try (Jedis jedis = jedisPool.getResource())
|
||||||
|
{
|
||||||
|
jedis.publish("session." + uuid, websocketGson.toJson(response, WebsocketMessage.class));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping("/logout")
|
@RequestMapping("/logout")
|
||||||
|
|||||||
Reference in New Issue
Block a user