def comment_latest_get(): rc = create_connection() response = rc.xrevrange('chat', '+', '-', 'COUNT', '20') logging.info('latest response : %s', response) return {'response': stream_data_to_json(response)}
def comment_add(): body = app.current_request.json_body logging.info('add request POST request Body : %s', body) rc = create_connection() response_xadd = rc.xadd('chat', '*', 'name', body['name'], 'comment', body['comment']) return {'state': 'Commment add OK', 'comment_seq_id': response_xadd}
def index(): # server status check URI now = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] rc = create_connection() rc.set('key1', now) result = rc.get('key1') return {'status': 'server status is good! ' + result}
def comment_seq_get(latest_seq_id): latest_list = latest_seq_id.split('-') logging.info('latest comments GET request latest seq id : %s', *latest_list) # Increment redis streams data type latest seq id # To get next comments next_id = int(latest_list[1]) next_id += 1 next_seq_id = f'{latest_list[0]}-{next_id}' logging.info('next seq id : %s', next_seq_id) rc = create_connection() response = rc.xrange('chat', next_seq_id, '+') logging.info('latest comments next id response : %s', response) return {'response': stream_data_to_json(response)}
def comment_all_get(): rc = create_connection() response = rc.xrange('chat', '-', '+') logging.info('comment all response : %s', response) return {'response': stream_data_to_json(response)}