Skip to content

Instantly share code, notes, and snippets.

@ikarius
Created February 8, 2010 14:13
Show Gist options
  • Save ikarius/298163 to your computer and use it in GitHub Desktop.
Save ikarius/298163 to your computer and use it in GitHub Desktop.
Simple use of Gredis
/**
* Some sample code...
* User: fred
* Date: 8 févr. 2010
* Time: 11:51:51
*/
// Create a new connection on localhost (assuming that a redis server is launched on default port)
Gredis g = new Gredis().connect()
// Add some keys
Key k = g.newKey('aKey', 'aValue')
assert 'aValue' == k.get()
// same as
assert 'aValue' == g['aKey']
// or
assert 'aValue' == k.value
// Delete a key
assert k.delete()
// same as
g.delete('aKey')
assert !g.exists('aKey')
// same as
assert !k.exists()
// Some list stuffs
g.delete('aList')
List list = g.newList('aList')
list << 'aValue' << 'anotherValue'
list.push('aThirdValue', true)
list.push('headValue')
// Get all values of list
assert ['headValue', 'aValue', 'anotherValue', 'aThirdValue'] == list.all()
// or some values only (ranges)
assert ['headValue', 'aValue'] == list[0..1]
g.close()
println 'Bye Gredis !'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment