Skip to content

Instantly share code, notes, and snippets.

@digininja
Last active January 5, 2016 21:41
Show Gist options
  • Save digininja/e5e16b285232ebf0c1df to your computer and use it in GitHub Desktop.
Save digininja/e5e16b285232ebf0c1df to your computer and use it in GitHub Desktop.
Redis increase and dump
require "redis"
redis = Redis.new
redis.flushdb
redis.zincrby("colours", 1, "red")
redis.sadd("colours:base:red", "thread")
redis.zincrby("colours", 1, "red")
redis.sadd("colours:base:red", "red box")
redis.zincrby("colours", 1, "green")
redis.zincrby("colours", 1, "blue")
redis.sadd("colours:base:blue", "bluebird")
redis.zincrby("colours", 1, "blue")
redis.zincrby("colours", 1, "red")
redis.zincrby("lengths", 1, "8")
redis.zincrby("lengths", 1, "8")
redis.zincrby("lengths", 1, "9")
redis.zincrby("lengths", 1, "9")
redis.zincrby("lengths", 1, "1")
redis.zincrby("lengths", 1, "7")
redis.zincrby("lengths", 1, "6")
redis.zincrby("lengths", 1, "8")
redis.zincrby("lengths", 1, "8")
redis.zincrby("lengths", 1, "8")
1.upto 20 do |i|
redis.zincrby("lengths", 1, i.to_s)
end
cap = 10
# Colours and their base words
puts "Colours"
range = redis.zrevrange("colours", 0, cap - 1, :with_scores => true)
range.each do |key_value|
key = key_value[0]
puts "Base word: #{key}"
members = redis.smembers("colours:base:#{key}")
puts "Taken from: #{members.join(',')}"
end
puts
# Just lengths
puts "Lengths"
range = redis.zrevrange("lengths", 0, cap - 1, :with_scores => true)
puts range.inspect
# Empty, returns empty array
puts "Days"
range = redis.zrevrange("days", 0, cap - 1, :with_scores => true)
puts range.inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment