Sha256: 3b3245ba661c260014c9271ac74920839b439b6ae7254de42a44d7220c31871f

Contents?: true

Size: 660 Bytes

Versions: 2

Compression:

Stored size: 660 Bytes

Contents

module Blendris

  # RedisSet is a wrapper to the Redis SET data type.

  class RedisSet

    include RedisNode
    include Enumerable

    def initialize(key, options = {})
      @key = key.to_s
      @options = options
      @on_change = options[:on_change]
    end

    def each
      redis.smembers(key).each do |value|
        yield value
      end

      self
    end

    def <<(value)
      [ value ].flatten.compact.each do |v|
        redis.sadd key, v
      end

      self
    ensure
      notify_changed
    end

    def get
      self
    end

    def delete(value)
      redis.srem key, value
    ensure
      notify_changed
    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blendris-0.0.4 lib/blendris/set.rb
blendris-0.0.3 lib/blendris/set.rb