RedisTemplate 不支持PUBSUB CHANNELS命令。所以一种方法是执行以下操作
private JedisPool getJedisPool(){
if (jedisPool == null)
jedisPool = new JedisPool(redisConnectionFactory.getPoolConfig(), redisConnectionFactory.getHostName(), redisConnectionFactory.getPort());
return jedisPool;
}
public Integer getNumChannels() {
Integer count = 0;
try (Jedis jedis = getJedisPool().getResource()) {
List<String> channels = jedis.pubsubChannels("user.*");
count = channels == null ? 0 : channels.size();
} catch (Exception e) {
logger.error("unable to get user count", e);
} finally {
//getJedisPool().close(); //No need for close or returnResource()
}
}
这是建议的方法吗?