github.com/iron-io/functions@v0.0.0-20180820112432-d59d7d1c40b2/examples/redis/README.md (about)

     1  # Redis GET/SET Function Image
     2  
     3  This function basically executes a GET/SET in a given redis server.
     4  
     5  ## Requirements
     6  
     7  - Redis Server
     8  - IronFunctions API
     9  
    10  ## Development
    11  
    12  ### Building image locally
    13  
    14  ```
    15  # SET BELOW TO YOUR DOCKER HUB USERNAME
    16  USERNAME=YOUR_DOCKER_HUB_USERNAME
    17  
    18  # build it
    19  ./build.sh
    20  ```
    21  
    22  ### Publishing to DockerHub
    23  
    24  ```
    25  # tagging
    26  docker run --rm -v "$PWD":/app treeder/bump patch
    27  docker tag $USERNAME/func-redis:latest $USERNAME/func-redis:`cat VERSION`
    28  
    29  # pushing to docker hub
    30  docker push $USERNAME/func-redis
    31  ```
    32  
    33  ### Testing image
    34  
    35  ```
    36  ./test.sh
    37  ```
    38  
    39  ## Running it on IronFunctions
    40  
    41  ### Let's define some environment variables
    42  
    43  ```
    44  # Set your Function server address
    45  # Eg. 127.0.0.1:8080
    46  FUNCAPI=YOUR_FUNCTIONS_ADDRESS
    47  
    48  # Set your Redis server address
    49  # Eg. redis:6379
    50  REDIS=YOUR_REDIS_ADDRESS
    51  
    52  # Set your Redis server auth (if required)
    53  REDIS_AUTH=REDIS_AUTH_KEY
    54  ```
    55  
    56  ### Running with IronFunctions
    57  
    58  With this command we are going to create an application with name `redis`.
    59  
    60  ```
    61  curl -X POST --data '{
    62      "app": {
    63          "name": "redis",
    64          "config": {
    65              "server": "'$REDIS'"
    66              "redis_auth": "'$REDIS_AUTH'"
    67          }
    68      }
    69  }' http://$FUNCAPI/v1/apps
    70  ```
    71  
    72  Now, we can create our routes
    73  
    74  #### Route for set value
    75  
    76  ```
    77  curl -X POST --data '{
    78      "route": {
    79          "image": "'$USERNAME'/func-redis",
    80          "path": "/redis",
    81          "config": {
    82              "command": "SET"
    83          }
    84      }
    85  }' http://$FUNCAPI/v1/apps/redis/routes
    86  ```
    87  
    88  #### Route for get value
    89  
    90  ```
    91  curl -X POST --data '{
    92      "route": {
    93          "image": "'$USERNAME'/func-redis",
    94          "path": "/redis",
    95          "config": {
    96              "command": "GET"
    97          }
    98      }
    99  }' http://$FUNCAPI/v1/apps/redis/routes
   100  ```
   101  
   102  #### Testing function
   103  
   104  Now that we created our IronFunction route, let's test our new route
   105  
   106  ```
   107  curl -X POST --data '{"key": "name", "value": "Johnny"}' http://$FUNCAPI/r/redis/set
   108  // "OK"
   109  curl -X POST --data '{"key": "name"}' http://$FUNCAPI/r/redis/get
   110  // "Johnny"
   111  ```