Module: Fuzzzy::Redis

Included in:
MethodBase
Defined in:
lib/fuzzzy/redis.rb

Constant Summary collapse

INDEX_KEY =

Ruby implementation is: def index_key key, key2=nil

key = "#{key}:#key2" if key2
"#{shared_key}:#{index_key}:#{key}"

end

<<-EOC
VALUE 
_index_key(int argc, VALUE *argv, VALUE self) 
{
  VALUE type = rb_funcall(self, rb_intern("index_type"), 0);
  VALUE shared_key = rb_funcall(self, rb_intern("shared_key"), 0);
  char sep[2] = ":";
  VALUE key, key2, result;
  char * buf;
  unsigned long long length;

  if(rb_scan_args(argc, argv, "11", &key, &key2) == 2) {
    key = rb_str_dup(key);
    rb_str_cat(key, sep, 1);
    rb_str_concat(key, rb_funcall(key2, rb_intern("to_s"), 0));
  }

  length = RSTRING_LEN(shared_key) + RSTRING_LEN(type) + RSTRING_LEN(key) + 4;
  buf = malloc(length);
  snprintf(buf, length, "%s:%s:%s", RSTRING_PTR(shared_key), RSTRING_PTR(type), RSTRING_PTR(key));
  result = rb_str_new2(buf);
  free(buf);

  return result;
}
EOC

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.counter_keyObject



57
58
59
# File 'lib/fuzzzy/redis.rb', line 57

def self.counter_key
  "fuzzzy:indexes:info"
end

Instance Method Details

#counter_keyObject



53
54
55
# File 'lib/fuzzzy/redis.rb', line 53

def counter_key
  "fuzzzy:indexes:info"
end

#dictionary_key(id) ⇒ Object



49
50
51
# File 'lib/fuzzzy/redis.rb', line 49

def dictionary_key id
  "#{shared_key}:dictionary:#{id}"
end

#redisObject



41
42
43
# File 'lib/fuzzzy/redis.rb', line 41

def redis
  Fuzzzy.redis
end

#shared_keyObject



45
46
47
# File 'lib/fuzzzy/redis.rb', line 45

def shared_key
  context[:shared_key] ||= "fuzzzy:#{index_name}"
end