module RedisHash::Insertions

Public Instance Methods

[]=(field, value)
Alias for: store
merge!(other_hash) click to toggle source
# File lib/redis_hash/concerns/insertions.rb, line 13
def merge!(other_hash)
  assert_keys_allowed(other_hash.keys)
  run_callbacks(:insertion) { hmset(*other_hash.to_a.unshift(redis_key)) }

  self
end
Also aliased as: update
setnx(field, value) click to toggle source
# File lib/redis_hash/concerns/insertions.rb, line 38
def setnx(field, value)
  setnx!(field, value)
rescue RedisHash::AlreadyDefinedError
  false
end
setnx!(field, value) click to toggle source
# File lib/redis_hash/concerns/insertions.rb, line 27
def setnx!(field, value)
  assert_keys_allowed(field)
  run_callbacks(:insertion) do
    success = hsetnx(redis_key, field, value)

    raise RedisHash::AlreadyDefinedError, "#{field} already defined" unless success
  end

  true
end
store(field, value) click to toggle source
# File lib/redis_hash/concerns/insertions.rb, line 21
def store(field, value)
  assert_keys_allowed(field)
  run_callbacks(:insertion) { hset(redis_key, field, value) }
end
Also aliased as: []=
update(other_hash)
Alias for: merge!