| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import json
- import redis
- # Redis 连接
- r = redis.Redis(
- host="45.137.220.138",
- port=6379,
- db=0,
- password="STEs2x6ML0U1HlpE9SojM6YU7QPhqzY8",
- decode_responses=True
- )
- # topic/channel
- channel = "vs:signal:slot.lon.fr.tourist"
- # 消息体
- message = {
- "group_id": "tls.gb.fr",
- "apt_type": {
- "weight": 10,
- "routing_key": "slot.lon.fr.tourist",
- "city": "London",
- "visa_type": "Tourist",
- "country": "France"
- },
- "query_result": {
- "routing_key": "slot.lon.fr.tourist",
- "country": "France",
- "city": "London",
- "visa_type": "Tourist",
- "availability_status": "Available",
- "earliest_date": "2026-06-05",
- "availability": [
- {
- "date": "2026-06-05",
- "times": [
- {
- "time": "14:00",
- "label": ""
- }
- ]
- }
- ],
- "snapshot_source": "worker",
- "snapshot_at": "2026-05-02T14:23:45.123456+00:00"
- },
- "timestamp": 1777745853
- }
- # 发布
- receiver_count = r.publish(
- channel,
- json.dumps(message, ensure_ascii=False)
- )
- print(f"发布成功 -> {channel}")
- print(f"收到订阅者数量: {receiver_count}")
|