Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Ejemplo de un cliente publicador a un broker Redis
import time
import redis
import logging
from app_redis import config, exception
def start(redis_server: redis.Redis, max_message: int) -> bool:
Post a message on a Redis topic.
:param redis_server: redis.Redis
:param max_message
:return: bool
""""[##] Publishing message...")
if redis_server is None:
raise exception.PublishRedisException()
index = 0
while index < max_message:
msg = '{"message": "Test message-%d", "result": "OK"}' % index
redis_server.publish(config.TOPIC_REDIS, msg)"[##] Message wroten...{index}")
index += 1
return True
def main():"## Publish ##")
publish_redis = redis.Redis(host=config.HOST_REDIS, port=config.PORT_REDIS, db=0)"[##] Redis connected")
start(publish_redis, 100)
while True:
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment