Sha256: 18550c2bb6c8227e3854ed7a44357a87b67ac754759a91dbda315622df76990e

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

module Hari
  module Keys
    class Hash < Key

      def hash(name = nil)
        return super() unless name

        @name = name
        self
      end

      def hash!(name)
        @name = name
        to_h
      end

      def to_h
        Hari.redis.hgetall key
      end

      def delete(field)
        Hari.redis.hdel key, field
      end

      def key?(field)
        Hari.redis.hexists key, field
      end

      alias :has_key? :key?
      alias :member?  :key?

      def keys
        Hari.redis.hkeys key
      end

      def values
        Hari.redis.hvals key
      end

      def values_at(*keys)
        Hari.redis.hmget key, keys
      end

      def [](field)
        Hari.redis.hget key, field
      end

      def set(field, value)
        Hari.redis.hset key, field, value
      end

      alias :[]= :set

      def merge!(args = {})
        Hari.redis.hmset key, args.to_a.flatten
      end

      def count
        Hari.redis.hlen key
      end

      alias :size   :count
      alias :length :count

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
hari-0.0.5 lib/hari/keys/hash.rb