Nick Fisher's tech blog

Recent Posts

Subscribing to Redis Channels with Java, Spring Boot, and Lettuce

The source code for what follows can be found on Github.

Pub/Sub in redis allows a publisher to send things to subscribers without knowing who is actually subscribed. In a previous post, we covered a simple unit test for publishing and subscribing to lettuce, but if you want to have a subscription initialized on application startup, and respond to events, we’ll have to do a bit more, which I’ll demonstrate here.

Expiring Individual Elements in a Redis Set

The source code for what follows can be found on Github.

Redis does not allow you to set the expiration on individual members in a set, it only allows you to set an expiration on the entire set itself. If you want to have a sort of expiry on individual elements in a set, this article shares a workaround to that problem that works well in practice. Because I have already written a lot of boilerplate code for testing any redis operation using lettuce, I’m going to be showing you this technique using a reactive lettuce client, however the basic concept should transfer easily to any other client.

Newer Posts