SubThread.java 653 B

1234567891011121314151617181920212223242526
  1. package com.greentech.gateservice.redis;
  2. import redis.clients.jedis.Jedis;
  3. import redis.clients.jedis.JedisPool;
  4. public class SubThread extends Thread{
  5. private final JedisPool jedisPool;
  6. private final Subscriber subscriber = new Subscriber();
  7. public SubThread(JedisPool jedisPool) {
  8. this.jedisPool = jedisPool;
  9. }
  10. @Override
  11. public void run() {
  12. try (Jedis jedis = jedisPool.getResource()) {
  13. String channel = "channel:ptz:92";
  14. jedis.subscribe(subscriber, channel);
  15. } catch (Exception e) {
  16. System.out.printf("subscriber channel error, %s%n\n", e);
  17. }
  18. }
  19. }