Initial redis example

This commit is contained in:
Chris Patterson
2019-08-16 09:19:33 -04:00
parent c98edc03a8
commit b6ff35853e
4 changed files with 99 additions and 0 deletions

44
.github/workflows/redis-service.yml vendored Normal file
View File

@@ -0,0 +1,44 @@
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
container-job:
runs-on: ubuntu-latest
container:
image: node:10.16-jessie
services:
redis:
image: redis
ports:
- 6379:6379
steps:
- uses: actions/checkout@v1
- run: node client.js
env:
REDIS_HOST: redis
REDIS_PORT: ${{ job.services.redis.ports[6379] }}
vm-job:
runs-on: ubuntu-latest
services:
redis:
image: redis
ports:
- 6379/tcp
steps:
- uses: actions/checkout@v1
- run: node client.js
working-directory: ./redis
env:
REDIS_HOST: localhost
REDIS_PORT: ${{ job.services.redis.ports[6379] }}

19
redis/client.js Normal file
View File

@@ -0,0 +1,19 @@
const redis = require("redis");
redisClient = redis.createClient(process.env.REDIS_PORT, process.env.REDIS_HOST);
redisClient.on("error", function(err) {
console.log("Error " + err);
});
redisClient.set("string key", "string val", redis.print);
redisClient.hset("hash key", "hashtest 1", "some value", redis.print);
redisClient.hset(["hash key", "hashtest 2", "some other value"], redis.print);
redisClient.hkeys("hash key", function (err, replies) {
console.log(replies.length + " replies:");
replies.forEach(function (reply, i) {
console.log(" " + i + ": " + reply);
});
redisClient.quit();
});

31
redis/package-lock.json generated Normal file
View File

@@ -0,0 +1,31 @@
{
"requires": true,
"lockfileVersion": 1,
"dependencies": {
"double-ended-queue": {
"version": "2.1.0-0",
"resolved": "https://registry.npmjs.org/double-ended-queue/-/double-ended-queue-2.1.0-0.tgz",
"integrity": "sha1-ED01J/0xUo9AGIEwyEHv3XgmTlw="
},
"redis": {
"version": "2.8.0",
"resolved": "https://registry.npmjs.org/redis/-/redis-2.8.0.tgz",
"integrity": "sha512-M1OkonEQwtRmZv4tEWF2VgpG0JWJ8Fv1PhlgT5+B+uNq2cA3Rt1Yt/ryoR+vQNOQcIEgdCdfH0jr3bDpihAw1A==",
"requires": {
"double-ended-queue": "^2.1.0-0",
"redis-commands": "^1.2.0",
"redis-parser": "^2.6.0"
}
},
"redis-commands": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/redis-commands/-/redis-commands-1.5.0.tgz",
"integrity": "sha512-6KxamqpZ468MeQC3bkWmCB1fp56XL64D4Kf0zJSwDZbVLLm7KFkoIcHrgRvQ+sk8dnhySs7+yBg94yIkAK7aJg=="
},
"redis-parser": {
"version": "2.6.0",
"resolved": "https://registry.npmjs.org/redis-parser/-/redis-parser-2.6.0.tgz",
"integrity": "sha1-Uu0J2srBCPGmMcB+m2mUHnoZUEs="
}
}
}

5
redis/package.json Normal file
View File

@@ -0,0 +1,5 @@
{
"dependencies": {
"redis": "^2.8.0"
}
}