-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stats endpoint #2
Comments
Potential solutionTo implement the How to implementIn the
Here's the implementation: from flask import Flask, jsonify
import os
import redis
import dotenv
dotenv.load_dotenv()
app = Flask(__name__)
# Initialize Redis connection
redis_host = os.getenv('REDIS_HOST', 'localhost')
redis_port = int(os.getenv('REDIS_PORT', 6379))
redis_db = int(os.getenv('REDIS_DB', 0))
redis_client = redis.StrictRedis(host=redis_host, port=redis_port, db=redis_db)
@app.route('/stats', methods=['GET'])
def stats():
try:
# Replace 'cache_items' with the actual key used for storing items in Redis
item_count = redis_client.hlen('cache_items')
return jsonify({'item_count': item_count}), 200
except Exception as e:
return jsonify({'error': str(e)}), 500
# ... existing code ...
if __name__ == "__main__":
app.run(host="0.0.0.0", port=4000) In the
Here's the documentation update: ## Statistics Endpoint
The `/stats` endpoint provides insights into the cache performance by reporting the number of items currently stored in the Redis cache. This can help in evaluating the effectiveness of the caching strategy.
### Usage
To retrieve cache statistics, issue a GET request to the `/stats` endpoint:
```shell
curl http://0.0.0.0:4000/stats You will receive a response in JSON format with the count of items: {
"item_count": 1234
} AuthenticationCurrently, there is no authentication required to access the
Please note that the above code assumes that the Redis cache stores items in a hash named 'cache_items'. You will need to adjust the Redis command ( Also, ensure that the Redis environment variables ( Changes on docs/my-website/docs/proxy_server.mdTo address the task of updating the documentation to include information about the new
Here's an example of how the new section could look: ## Statistics Endpoint
The `/stats` endpoint allows users to monitor the performance of the cache by retrieving the current count of items stored in the Redis cache. This information can be useful for understanding the cache utilization and optimizing cache-related operations.
### Usage
To get the cache statistics, send a GET request to the `/stats` endpoint:
```shell
curl http://0.0.0.0:8000/stats The response will be a JSON object containing the count of items: {
"item_count": 1234
} Note: Replace AuthenticationNo authentication is required to access the
|
Add a
/stats
REST endpoint that explains how many items are currently in the Redis cache.I want to be able to evaluate cache performance.
@autopilot Please do this.
The text was updated successfully, but these errors were encountered: