cancel
Showing results for 
Search instead for 
Did you mean: 

issue with "Use Redis in the Kyma Runtime to Store and Retrieve Data" tutorial

hokandil
Explorer
0 Kudos

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]);
            }
gabbi
Product and Topic Expert
Product and Topic Expert

Hi Hossam,

Your Central gateway URL is wrong. You should take it from integration -> applications -> API (in Kyma dashboard)

Best regards,

Gaurav Abbi

Accepted Solutions (0)

Answers (0)