Skip to content

evanx/config-hmset

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

config-hmset

Containerized util to set Redis hashes from JS/JSON file

Implementation

Note that for properties that are not strings or numbers, we apply JSON.stringify

The implementation is essentially as follows:

const content = await getStdin();
const object = JSON.parse(content);
await multiExecAsync(redis, multi => {
    Object.keys(object).forEach(key => {
        const value = object[key];
        if (typeof value === 'object') {
            multi.hset(config.key, key, JSON.stringify(value));
        } else {
            multi.hset(config.key, key, value);
        }
    });
});

It's designed to be containerized:

echo '{"url": "https://news.ycombinator.com"}' |
  docker run -i --network=host -e redisHost=127.0.0.1 \
    -e key=myconfig evanxsummers/config-hmset
  • the image of the application container is evanxsummers/config-hmset (DockerHub)
  • JSON content is piped as standard input into docker run -i of this app image
  • the redisHost and hashes key are specified using -e (environment variables for the app)
  • the app will HMSET a Redis hashes key from the JSON input content

Note that since this is a container, usually redisHost it will not be localhost unless bridged e.g. via --network=host.

We can inspect the hashes key to verify that its fields were set as expected:

$ redis-cli hgetall myconfig
1) "url"
2) "https://news.ycombinator.com"

Docker image

The Docker image can be built as follows:

docker build -t config-hmset https://github.com/evanx/config-hmset.git

From the Dockerfile

FROM mhart/alpine-node
ADD package.json .
RUN npm install
ADD components components
ADD src src
CMD ["node", "--harmony", "src/index.js"]

Or use evanxsummers/config-hmset i.e. prebuilt on DockerHub.

You can check the version using npm as follows

$ docker run evanxsummers/config-hmset npm version | head -1
{ 'config-hmset': '0.2.0',

or

$ docker run evanxsummers/config-hmset cat package.json | grep version
  "version": "0.2.0",

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors