<jupyter_start><jupyter_text>Play with Redis<jupyter_code>redis_cnx = redis.Redis( host='redis', port=6379, db=0 )
redis_key1 = 'demo:key1'
value = 'hello world'
redis_cnx.set( redis_key1, value, ex=6000 )
value_from_cache = redis_cnx.get(redis_key1)
print(value_from_cache)<jupyter_output>b'hello world'<jupyter_text>Play with RabbitMQ<jupyter_code># Send a message to rabbitmq

def rabbitmq_connect(host, port, username, password):
    credentials = pika.PlainCredentials(username, password)
    connection = pika.BlockingConnection(pika.ConnectionParameters(host, port, credentials=credentials))
    channel = connection.channel()
    return connection, channel

rabbitmq_cnx, rabbitmq_channel = rabbitmq_connect('rabbitmq', 5672, 'guest', 'guest')
rabbitmq_channel.basic_publish(exchange='exchange1', routing_key='hello_topic', body='hello world from jupyter')
# send a single message
rabbitmq_channel.basic_publish(exchange='exchange1', routing_key='hello_topic', body='hello world from jupyter')
# send 100K messages
for i in range(100000):
    rabbitmq_channel.basic_publish(exchange='exchange1', routing_key='hello_topic', body='hello world from jupyter {}'.format(i))
rabbitmq_cnx.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1165444172779136, 'fraction_numerical': 0.023634881825590873, 'mean_word_length': 8.669291338582678, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '436699', 'license': 'MIT', 'n_tokens_mistral': 451, 'n_tokens_neox': 414, 'n_words': 81, 'path': 'jupyter-notebook/demo_rabbitmq.ipynb', 'repo_name': 'nbigot/tutorial_python_rabbitmq', 'size': '1227'}