Skip to content

Instantly share code, notes, and snippets.

@devdazed
Created January 13, 2011 17:41
Show Gist options
  • Save devdazed/778240 to your computer and use it in GitHub Desktop.
Save devdazed/778240 to your computer and use it in GitHub Desktop.
manage surrogate keys usign Redis
require 'redis'
require 'digest/sha1'
class RedisKey
def initialize
@redis = Redis.new
end
def surrogate_key(dimension, data)
nk = Digest::SHA1.hexdigest(data)
sk = @redis.get "#{dimension}/#{nk}"
unless sk
sk = @redis.incr "#{dimension}/key"
@redis.set "#{dimension}/#{nk}", sk
end
sk
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment