easy to use redis(kb)
Project description
Easy to use python redis(for kb first)
Compared with kafka, redis has the following characteristics in publishing and subscribing:
Produced messages are immediately consumed by consumers.
Fast speed, small data( < 10KB).
Allow message loss.
No need to save sent messages.
Quick Start
Installation: pip install easy_redis
1.config
Edit conf/conf.yml
redis: # redis config
server: 127.0.0.1 # redis server
port: 6379
channel_subscribe: # channel if need, multiple
- channel_1
- channel_2
channel_produce: channel_1_result # producer default channel
2.demo-consumer
import json
from easy_redis.redis_consumer import EasyRedisConsumer
def start_consumer():
redis_consumer = EasyRedisConsumer('../conf/conf.yml')
print('consumer iterator started')
for record in redis_consumer:
if record['type'] == 'message':
print('data', json.loads(record['data']))
else:
print('subscribe', record)
if __name__ == "__main__":
start_consumer()
3.demo-consumer-task
import json
from easy_redis.redis_consumer import EasyRedisConsumer
from easy_redis.redis_producer import EasyRedisProducer
redis_producer = EasyRedisProducer('../conf/conf.yml')
def consumer_task(record):
"""
consumer callback
:param record: object
:return:
"""
print('consumer_task', (
'received type: {}, channel: {}, msg: {}'.format(record['type'], record['channel'], record['data'])))
if record['type'] == 'message':
print('data', json.loads(record['data']))
if record['channel'] == 'channel_1':
redis_producer.produce_msg({'type': 'task result'})
def start_consumer():
redis_consumer = EasyRedisConsumer('../conf/conf.yml')
print('consumer task started')
redis_consumer.subscribe(fn=consumer_task)
if __name__ == "__main__":
start_consumer()
4.demo-producer
from easy_redis.redis_config import EasyRedisConfig
from easy_redis.redis_producer import EasyRedisProducer
def demo_produce_msg():
redis_producer = EasyRedisProducer('../conf/conf.yml')
redis_producer.produce_msg({'name': 'ksust'})
def demo_produce_msg_with_config():
config = EasyRedisConfig('../conf/conf.yml')
print('config', config.__dict__)
redis_producer = EasyRedisProducer(config)
redis_producer.produce_msg({'name': 'ksust'})
redis_producer.produce_msg_channel('channel_1', {'name': 'ksust'})
if __name__ == "__main__":
demo_produce_msg()
demo_produce_msg_with_config()
5.demo-redis_conn
from easy_redis.redis_conn import EasyRedis
def demo_redis():
redis_conn = EasyRedis('../conf/conf.yml').redis_conn
redis_conn.set('demo', 'value')
print(redis_conn.keys('*'))
if __name__ == "__main__":
demo_redis()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file easy_redis-0.0.4.tar.gz.
File metadata
- Download URL: easy_redis-0.0.4.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95e2c2cf0be311557afb13acc5725df9df64654e4cc0462fffc6a195eb9cd9fb
|
|
| MD5 |
d00221ee213cba96499a1ed1735867f3
|
|
| BLAKE2b-256 |
20536f7adeb5215cb1f31193a117ee5f1f20df58bc0944fd39c061d092e9168a
|
File details
Details for the file easy_redis-0.0.4-py3-none-any.whl.
File metadata
- Download URL: easy_redis-0.0.4-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e55cd144c13f463825d414bb68e0d6605d900f0e44405a513322778212bf8d1e
|
|
| MD5 |
57804544fd5011cebab3313f71cfe352
|
|
| BLAKE2b-256 |
53a30a4ee67fb1f84c1ecb6db84cd57c65493d864544c4f6dda7d7c09569b261
|