mirror of
https://github.com/storytold/EventCenterPlugin.git
synced 2026-10-09 00:09:42 +00:00
wip python server; I'll need async redis
This commit is contained in:
@@ -1,3 +1,52 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
print('testing on windowz, no idea how that works')
|
import asyncio
|
||||||
|
import redis
|
||||||
|
import sys
|
||||||
|
import websockets
|
||||||
|
|
||||||
|
#redis_client = redis.Redis(host='localhost', port=6379, db=0)
|
||||||
|
|
||||||
|
pool = redis.ConnectionPool(host='localhost', port=6379, password='', db=0)
|
||||||
|
redis_pool = redis.StrictRedis(connection_pool=pool)
|
||||||
|
#redis_connection = redis_pool.redis_connect()
|
||||||
|
|
||||||
|
#pubsub = redis_connection.pubsub()
|
||||||
|
pubsub = redis_pool.pubsub()
|
||||||
|
pubsub.subscribe('testing')
|
||||||
|
pubsub.subscribe('foo')
|
||||||
|
|
||||||
|
#for message in pubsub.listen():
|
||||||
|
# if message['data'] == 'exit':
|
||||||
|
# sys.exit()
|
||||||
|
# print(message)
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
async def hello(websocket, path):
|
||||||
|
name = await websocket.recv()
|
||||||
|
print(f"< {name}")
|
||||||
|
|
||||||
|
greeting = f"Hello {name}!"
|
||||||
|
|
||||||
|
await websocket.send(greeting)
|
||||||
|
print(f"> {greeting}")
|
||||||
|
|
||||||
|
start_server = websockets.serve(hello, "localhost", 8765)
|
||||||
|
|
||||||
|
asyncio.get_event_loop().run_until_complete(start_server)
|
||||||
|
asyncio.get_event_loop().run_forever()
|
||||||
|
"""
|
||||||
|
|
||||||
|
async def time(websocket, path):
|
||||||
|
while True:
|
||||||
|
now = datetime.datetime.utcnow().isoformat() + "Z"
|
||||||
|
await websocket.send(now)
|
||||||
|
await asyncio.sleep(random.random() * 3)
|
||||||
|
|
||||||
|
start_server = websockets.serve(time, "127.0.0.1", 5678)
|
||||||
|
|
||||||
|
asyncio.get_event_loop().run_until_complete(start_server)
|
||||||
|
asyncio.get_event_loop().run_forever()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user