on 10-22-2022 4:50 PM
the cache-order function yaml file from github on The tutorial "Use Redis in the Kyma Runtime to Store and Retrieve Data" is giving error whenever I try to deploy it
I had to do some changes in order to make it run.
apiVersion: serverless.kyma-project.io/v1alpha2
kind: Function
metadata:
name: cache-order
spec:
buildResources: {}
deps: |-
{
"axios": "^0.18.1",
"redis": "^3.0.2",
"handy-redis":"^2.0.0"
}
env:
- name: SITE
value: electronics
- name: REDIS_PORT
value: '6379'
- name: REDIS_PASSWORD
value: kPppOZp2hC
- name: REDIS_HOST
value: redis.dev.svc.cluster.local
- name: CENTRAL_GATEWAY_URL
value: kyma-gateway.kyma-system.svc.cluster.local
maxReplicas: 1
minReplicas: 1
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
runtime: nodejs16
source: |-
const axios = require("axios");
const hredis = require("handy-redis");
const COMM_GATEWAY_URL = process.env["CENTRAL_GATEWAY_URL"];
const client = hredis.createNodeRedisClient({
port: process.env["REDIS_PORT"],
host: process.env["REDIS_HOST"],
password: process.env["REDIS_PASSWORD"]
});
module.exports= {
main: async function (event, context) {
const orderCode = event.data.orderCode
console.log("Processing event with orderCode: ", orderCode);
const response = await getOrderDetails(orderCode);
const orderValue = response.totalPriceWithTax.value;
console.log("Received order value of: ", orderValue, " for orderCode: ", orderCode);
cacheOrder(orderCode, orderValue, client);
}
}
async function getOrderDetails(orderCode) {
const ordersUrl = `${COMM_GATEWAY_URL}/${process.env.SITE}/orders/${orderCode}`;
console.log("Getting ordering details via: %s", ordersUrl, " for orderCode:", orderCode);
const response = await axios.get(ordersUrl);
console.log(JSON.stringify(response.data, null, 2));
return response.data;
}
function cacheOrder(orderCode, orderValue){
console.log("Caching data to redis for orderCode: ", orderCode);
var orderDate = new Date();
return client.hmset(orderCode, ["orderCode", orderCode ], ["Date", orderDate], ["Value", orderValue]);
}
User | Count |
---|---|
75 | |
10 | |
8 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.