A simple Redis client written in Groovy and using Jedis

We’re testing some code which publishes data to Redis and we wrote the script below.

@GrabResolver(name='Maven Central', root='http://repo1.maven.org/')
@Grab(group='redis.clients', module='jedis', version='2.1.0')
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")

redis key value database, jedis connection pool, redis cache database, redis usage examples, redis pubsub java, redis pub sub queue, jedis pub sub

Leave a Reply

Your email address will not be published. Required fields are marked *