Skip to content

Instantly share code, notes, and snippets.

@revans
Created November 6, 2009 18:05
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 revans/228152 to your computer and use it in GitHub Desktop.
Save revans/228152 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'redis'
r = Redis.new
p 'set foo to "bar"'
r['foo'] = 'bar'
p 'value of foo'
p r['foo']
puts
p '*' * 80
p 'incr'
r.delete 'counter'
p r.incr('counter')
p r.incr('counter')
p r.incr('counter')
p 'decr'
p r.decr('counter')
p r.decr('counter')
p r.decr('counter')
r.delete 'logs'
puts
p '*' * 80
p "pushing log messages into a LIST"
r.push_tail 'logs', 'some log message'
r.push_tail 'logs', 'another log message'
r.push_tail 'logs', 'yet another log message'
r.push_tail 'logs', 'also another log message'
puts
p '*' * 80
p 'contents of logs LIST'
p r.list_range 'logs', 0, -1
puts
p '*' * 80
p 'Trim logs LIST to last 2 elements(easy circular buffer)'
p r.list_range 'logs', 0, -1
puts
p '*' * 80
p 'create a set of tags on foo-tags'
r.set_add 'foo-tags', 'one'
r.set_add 'foo-tags', 'two'
r.set_add 'foo-tags', 'three'
puts
p '*' * 80
p "create a set of tags on bar-tags"
r.set_add 'bar-tags', 'three'
r.set_add 'bar-tags', 'four'
r.set_add 'bar-tags', 'five'
puts
p '*' * 80
p 'foo-tags'
p r.set_members 'foo-tags'
puts
p '*' * 80
p 'bar-tags'
p r.set_members 'bar-tags'
puts
p '*' * 80
p 'intersection of foo-tags and bar-tags'
p r.set_intersect 'foo-tags', 'bar-tags
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment