Sha256: 95aa6a2170f0e2670a66caf939a11c3d4037c9feb93d60ecd6e173be11187177

Contents?: true

Size: 814 Bytes

Versions: 1

Compression:

Stored size: 814 Bytes

Contents

require "active_support/core_ext/hash"

class Kredis::Types::Hash < Kredis::Types::Proxying
  proxying :hget, :hset, :hmget, :hdel, :hgetall, :hkeys, :hvals, :del

  attr_accessor :typed

  def [](key)
    string_to_type(hget(key), typed)
  end

  def []=(key, value)
    update key => value
  end


  def update(**entries)
    hset types_to_strings(entries) if entries.flatten.any?
  end

  def values_at(*keys)
    strings_to_types(hmget(keys) || [], typed)
  end

  def delete(*keys)
    hdel types_to_strings(keys) if keys.flatten.any?
  end

  def remove
    del 
  end

  def entries
    (hgetall || {}).transform_values { |val| string_to_type(val, typed) }.with_indifferent_access
  end
  alias to_h entries

  def keys
    hkeys || []
  end

  def values
    strings_to_types(hvals || [], typed)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
kredis-0.3.0 lib/kredis/types/hash.rb