In the leadup to JavaOne, I whipped up a little competition app in Grails using the new Redis support. Graeme has written up a great GORM for Redis intro post that gives you all the info you need to get underway, so I’ll just add my experience to those interested. Here’s my little JavaOne competition app in action:
If you haven’t played with Redis before, think of it as a supercharged memcached. Except, of course, It’s persistent, and the values can be sets and lists.
First up, you’ll need a redis binary to run on your system. I’m developing on Windows these days, and you can get a Windows Redis binary. It’s just a few files that you can unzip where you please. Fire up redis-server.exe and you’re off and running
As for the Grails side, you’ll want to “grails uninstall-plugin hibernate”, since I’m using just redis without any other SQL stores. Check out Graeme’s post to learn how you can mix and match hibernate and Redis in the same app.
So what other changes did I need to make to store my data in Redis? None! Graeme’s done all the hard work of implement all the basic GORM stuff (including dynamic finders) right into the Redis plugin! Rock on!
One neat feature I did take advantage off is Redis unique support for random() selection of data elements. For example, I selected my competition winner by implementing the following code:
def winner = { log.debug "Generating random winner" Submission winningSub = Submission.random() render "${winningSub.contestant.name} - ${winningSub.dTerm.name} ${winningSub.sTerm.name} ${winningSub.lTerm.name}" }
So the takeaway from all this is… if you’ve been keen to explore some NoSQL options, there’s never been a better time to have a look at Grails Redis support and dip your toes in the NoSQL waters. Having GORM support makes it insanely easy to experiment with your NoSQL store.
If you want to see how Grails is interacting with Redis, fire up redis-client, then issue the “monitor” command. You’ll see how GORM is doing its reads and writes against your Redis store. Interesting sets flying around the place!
Looking for docs? There’s a fantastic manual available, which even covers some of the new testing stuff (which lets you test against a ConcurrentHashMap rather than having to spark up a Redis instance!).
If you’re keen to have a look at my little demo, feel free to clone the BitBucket repo and have fun! I’m thinking we’re going to have to include NoSQL section in the next Grails in Action…