Skip to content

Instantly share code, notes, and snippets.

@thospfuller
Created April 12, 2021 03:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thospfuller/1821b8d3ce65994d4a2d6945982a0475 to your computer and use it in GitHub Desktop.
Save thospfuller/1821b8d3ce65994d4a2d6945982a0475 to your computer and use it in GitHub Desktop.
A simple Redis client written in Groovy and using Jedis
@GrabResolver(name='Maven Central', root='http://repo1.maven.org/')
@Grab(group='redis.clients', module='jedis', version='3.5.2')
import redis.clients.jedis.Jedis
import redis.clients.jedis.JedisPubSub
class DefaultPubSubImpl extends JedisPubSub {
@Override
public void onMessage(String channel, String message) {
println "channel: $channel, message: $message"
}
@Override
public void onPMessage(String pattern, String channel, String message) {}
@Override
public void onSubscribe(String channel, int subscribedChannels) {}
@Override
public void onUnsubscribe(String channel, int subscribedChannels) {}
@Override
public void onPUnsubscribe(String pattern, int subscribedChannels) {}
@Override
public void onPSubscribe(String pattern, int subscribedChannels) {}
}
def subscriber = new DefaultPubSubImpl ()
Jedis jedis = new Jedis("localhost", 6379, 0)
jedis.connect();
jedis.subscribe (subscriber, "updates")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment