mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
564 B
28 lines
564 B
import redis
|
|
from django.conf import settings
|
|
|
|
|
|
def get_redis_client(db):
|
|
rc = redis.StrictRedis(
|
|
host=settings.REDIS_HOST,
|
|
port=settings.REDIS_PORT,
|
|
password=settings.REDIS_PASSWORD,
|
|
db=db
|
|
)
|
|
return rc
|
|
|
|
|
|
class RedisPubSub:
|
|
def __init__(self, ch, db=10):
|
|
self.ch = ch
|
|
self.redis = get_redis_client(db)
|
|
|
|
def subscribe(self):
|
|
ps = self.redis.pubsub()
|
|
ps.subscribe(self.ch)
|
|
return ps
|
|
|
|
def publish(self, data):
|
|
self.redis.publish(self.ch, data)
|
|
return True
|