Redis Hackathon Submission


I participated in a Redis Hackathon hosted on Dev.to which required use of the Redis Stack. Anyone familiar with Redis knows it for its primary use case as a cache, with popular adoption as a primary database because of its ease-of-use and high developer happiness as part of the ecosystem’s DX metric.

The hackathon started at the beginning of August but I started late and had to balance free time against work time. The submission deadline was August 29 at 7 PM. Though I didn’t have a finalized submission, just for participating I’ve gotten a $500 credit for Redis Stack!

Redis Stack

The Redis Stack is a distributed system! Redis has multiple projects, meaning multiple parts of these applications can run in a distributed system to provide a single endpoint for a full-featured cache. Redis means Remote Dictionary server, which is what they call the initial redis app which is historically compared to memcached.

Redis Stack is made up of several components, licensed as follows:

Redis Stack Server, which combines open source Redis with RediSearch, RedisJSON, RedisGraph, RedisTimeSeries, and RedisBloom, is licensed under the Redis Source Available License (RSAL).

RedisInsight is licensed under the Server Side Public License (SSPL).

Using these combined systems, I made a microservice app which enabled me to create an endpoint to easily store some data for the michaellamb.dev Discord bot. The project I came up with involved integrating Midjourney image generation and a frontend.

The progress I did make

The following sections will be dated entries with commits SHAs and descriptions of the changes.

August 17

1 commit

This is just the basic initialization of the app. It builds and runs. Swagger is available.

August 20

1 commit

message: creates example People repository

I’m following along with the Stack Spring tutorial here to implement some basic functionality. This includes using the skeleton app repo as a reference.

Progress here includes connecting to the Redis Stack. Of course, the password has been changed since this is open source. A future commit will rename the application.properties file to indicate it is an example only, after another commit which adds an entry for application.properties in .gitignore.

August 22

3 commits

message: ignore application.properties

message: Update .gitignore

message: Rename application.properties to last-application.properties

This does the things I said in the last description.

August 23

message: migrate to springdoc

Springfox doesn’t support something in Spring 2.7.0 so I migrated the project to Springdoc.

message: replaced import

Fixed an erroneous import in the Person domain class.

message: implement RedisDocumentRepository operations

This adds functionality around the Person objects using RedisDocumentRepository to generate boilerplate code. We can easily return an Iterable<Person> with whatever data points we can imagine because of the power of Redis. The OM library gives us the ability to stub basic methods. We can use these to query Redis for data.

message: add controller operations

This exposes the functionality of the PeopleRepository as an API.

August 24

message: refactor Person

These chisel down some of the fields on the Person class

message: remove loadTestData CommandLineRunner

This is tutorial code and should be removed before further development.

message: fix build

I’m not perfect.

Reflection

I got a good deal of exposure to Redis OM Spring and more experience with RedisInight, the GUI used to inspect Redis databases. I ran into issues with the meta-model generation, I’m not sure if that was because VS Code doesn’t know about meta-modeling or if I was missing a Maven compilation step. Overall, Redis OM Spring seems like it’s headed in a good direction!

My code is not production ready but it’s progress.

Music Corner


Authored by Michael Lamb.
Published on 30 August 2022.


Spring Boot App as a Service


Docker as a deployment strategy can have its shortcomings. One shortcoming I experienced recently was a breakdown in being able to make requests and receive responses from other michaellamb.dev apps and the Spring Boot demo app.

Instead of fighting with Docker (a tool I’m less familiar with) I opted to install the Spring Boot application as a service on a single node. This process could be automated using a CI/CD strategy and I may implement something using GitHub Actions in the future, but it is a more involved process than pulling a Docker image and running it as a container.

Baeldung wrote an article I used as a guide for installing the Spring Boot demo app as a service on Linux.

Maven Configuration

The first step is to enable the executable flag in the spring-boot-maven-plugin referenced in pom.xml


<configuration>
    <executable>true</executable>
</configuration>

See this change in the linked commit: update pom

Build

The second step is to copy the source code to the node and package it for deployment.


./mvwn clean package

It may be necessary to change directory permissions to allow the app to read and write using the file system.

System V Init

Using the traditional System V init, we create a symbolic link that we can use to reference as a service.


sudo ln -s /home/michael/demo/target/demo-0.1.0.jar /etc/init.d/demo

This link would need to be updated any time the jar is renamed

The app needs to be enabled by the system using the following command:


sudo systemctl enable demo

Once the system knows the app is available as a service, the service can be started.


sudo service demo start

Other commands are available using the standard service script: stop, restart, and status. Moreover, logs can be viewed under var/log/demo.log.


Authored by Michael Lamb.
Published on 17 August 2022.
Category: Spring


MagnoliaJS 2022


MagnoliaJS Conference 2022

The MagnoliaJS Conference was first founded by J.C. Hiatt in 2019. Since then, the conference has connected over 450 members on Discord alone! Web development and software engineering go hand in hand, so naturally I’m interested in a lot of the topics that are discussed at MagnoliaJS events. I plan on taking part in this exciting conference and I’m hopeful that you might find it interesting too! I’ve collected all the details I personally would care about here (I’m being selfish because I will be referencing this during the event myself and I’m just writing it ahead of time).

September 13th–14th, 2022

380 South Lamar Street, Jackson MS 39201

Jackson, MS events

  • Opening night mixer @ The Westin Jackson (407 S Congress St, Jackson, MS 39201)
  • Day 1 Evening Social @ MS Museum of Art (conference venue)
  • Conference Afterparty @ JXN Tech District google maps, twitter

Speakers

  • Cloudinary
  • FlightControl
  • CircleCI
  • Morgan White Group

Authored by Michael Lamb.
Published on 02 August 2022.
Category: Social


Using Discord4J in Spring Boot


It’s been a minute

I fell off the blog-writing momentum once JXN Film Club’s Summer Movie Nights kicked into high gear. Balancing blog-writing and a film club and a full-time job is a lot of time!

I’ve still been writing my own bits of software, as always, so I figured I’d give some insight into what I’ve been working on.

michaellamb.dev on Discord

If you’re reading this, you’ve probably seen the Discord server widget in the About Me section. Clicking on it or visiting this link will get you into the official michaellamb.dev server. Come chat with me!

Discord4J

I had a pretty simple problem which motivated me to stand up a Discord bot: I run a Valheim dedicated server for myself and other friends on Discord but beyond attempting to connect to the server in-game there wasn’t an easy way to see the server’s status or if anyone was online.

Connecting the Steam Web API to Uptime Kuma, my status montioring app, let me track the uptime of the game server. The app supports the creation of multiple status pages, so I added valheim.michaellamb.dev and pinned a message with connection details.

Where the Discord bot comes in is updating its presence to a status message. Bots and members alike can have a presence status, indicating a current activity. The michaellamb.dev bot has a presence shown below.

michaellamb.dev bot, presence status: "Playing Valheim, 0/10 online"

Agent Logic

I won’t go into the how to set up a Discord bot using Discord4J, their docs can do that better than I can. Let’s just look at the agent logic used to update the presence.


    @Scheduled(fixedRate = 1, timeUnit = TimeUnit.MINUTES)
    @Override
    public void checkValheimPlayerCount() {
        try {
            SteamGameServerStatusResponse response = steamGameServerService.getValheimInstanceStatus();

            if (response.isNotEmpty()) {
                SteamGameServerStatusResponse.Server valheimServer = response.getResponse().getServers().get(0);
                playerCount.set(valheimServer.getPlayers());
                String activity = String.format("Valheim | %d/10 Online", playerCount.get());

                LOG.info("valheimServer [{}], playerCount [{}], activity [{}]",
                valheimServer.toString(),
                playerCount.toString(),
                activity.toString());

                LOG.info("Updating ClientPresence with ClientActivity for Valheim");
                client.updatePresence(ClientPresence.online(ClientActivity.playing(activity)))
                .block();
            } else {
                LOG.info("Updating ClientPresence with ClientActivity for idling");
                client.updatePresence(ClientPresence.online(ClientActivity.streaming("status.michaellamb.dev", STATUS_URL)))
                .block();
            }
        } catch (Exception e) {
            LOG.error("An exception occurred", e);
        }
    }

The @Scheduled annotation tells Spring Boot to invoke this method on the given schedule, in this instance once per minute. Everything else is straightforward: we invoke steamGameServerService.getValheimInstanceStatus() and store it in response.

It may be helpful to know what Steam Web API sends back in a response here before moving on, so I’ve included the response that we should receive when the Valheim server is up.


{
    "response": {
        "servers": [{

            "addr": "173.235.136.46:2457",

            "gameport": 2456,
            "steamid": "90158276832560132",
            "name": "michaellamb",
            "appid": 892970,
            "gamedir": "valheim",

            "version": "1.0.0.0",

            "product": "valheim",
            "region": -1,
            "players": 0,
            "max_players": 64,
            "bots": 0,
            "map": "michaellamb",
            "secure": false,
            "dedicated": true,
            "os": "w",

            "gametype": "0.208.1"

        }]
    }
}

If the response comes back with an empty array of servers then we consider the game server to be down. If this happens, then bot presence is updated to an “idling” fallback status. Otherwise, the bot looks at response.servers.players and updates the total number of players in the tracking variable playerCount.

You may be wondering whether this agent/business logic is designed with other servers in mind. The service layer which handles the request/response to and from the Steam Web API specifically filters by appid, meaning that only Valheim game servers will be returned in this particular response.

This simple task felt like a good introduction to using Discord4J. It’s well-supported and is compatible with the Spring ecosystem.

Future

I use Discord webhooks with Uptime Kuma to get notifications when services go up or down, but I’d like to be able to fetch other stats from Uptime Kuma that are only accessible via the dashboard. The dashboard is LAN only so I’d have to use my self-hosted VPN to be able to look at it. Future work may include integrating slash commands to the bot which fetches this data and displays it.

Lately


Authored by Michael Lamb.
Published on 13 July 2022.
Category: Spring


GitHub Discussions - Spring Boot Demo App


Now Announcing GitHub Discussions

GitHub features a Discussions pane on code repositories so that communities can share thoughts and feedback without having to open a new issue.

This post is to announce that I want YOU to leave a comment on my announcement post over on GitHub. My blog is more informative than interactive (and I like it that way) but GitHub as a tool for organizing community around code is right up my alley. I hope you’ll join me and we can connect.

Follow this link to see the Discussion announcement.

discussions #1

Leave a comment on my announcement post

And when you’re done, check out the repo! I’ve enabled Discussion on my Spring Boot Demo app and there’s simply no reason you shouldn’t pull the code, try it out yourself, and then come back to the Discussions pane to tell me what you learned.

BE KIND ONLINE


Authored by Michael Lamb.
Published on 04 May 2022.
Category: Social



About michaellamb.dev

Michael Lamb is a software engineer working at C Spire. If you have a blog-specific inquiry please create a new issue on GitHub. Feel free to fork this blog and build your own!

Get to know who I am in my first post Hello, World!

© Copyright 2021-2025
Michael Lamb Blog