Sha256: 3c060a9f2522decf452cd7c3ad40497ba846856d4dcc8284e089a6d0528f3280

Contents?: true

Size: 1.03 KB

Versions: 6

Compression:

Stored size: 1.03 KB

Contents

module Ohm

  # Represents a key in Redis. Much of the heavylifting is done using the
  # Nest library.
  #
  # The most important change added by {Ohm::Key} to Nest is the concept of
  # volatile keys, which are used heavily when doing {Ohm::Model::Set#find} or
  # {Ohm::Model::Set#except} operations.
  #
  # A volatile key is simply a key prefixed with `~`. This gives you the
  # benefit if quickly seeing which keys are temporary keys by doing something
  # like:
  #
  #     $ redis-cli keys "~*"
  #
  # @see http://github.com/soveran/nest
  class Key < Nest
    def volatile
      self.index("~") == 0 ? self : self.class.new("~", redis)[self]
    end

    # Produces a key with `other` suffixed with itself. This is primarily
    # used for storing SINTERSTORE results.
    def +(other)
      self.class.new("#{self}+#{other}", redis)
    end

    # Produces a key with `other` suffixed with itself. This is primarily
    # used for storing SDIFFSTORE results.
    def -(other)
      self.class.new("#{self}-#{other}", redis)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ohm-0.1.5 lib/ohm/key.rb
ohm-0.1.4 lib/ohm/key.rb
ohm-0.1.3 lib/ohm/key.rb
ohm-0.1.2 lib/ohm/key.rb
ohm-0.1.1 lib/ohm/key.rb
ohm-0.1.0 lib/ohm/key.rb