Sha256: 9b6f4d9fba0d19b6ec17e91e0aa2d20bbc5dbb4a272a42db85af7f4e0cb58bee

Contents?: true

Size: 1.51 KB

Versions: 4

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

class ActiveRedisDB::Set < ActiveRedisDB::Base
  class << self

    def find(key)
      value = client.smembers(normalize_key(key))
      metatransform(value)
    end

    def combine(*args)
      value = client.sunion(*args)
      metatransform(value)
    end

    def difference(*args)
      value = client.sdiff(*args)
      metatransform(value)
    end

    def intersection(key, *args)
      value = client.sinter(normalize_key(key), *args)
      metatransform(value)
    end

    def sample(key, value = 1)
      value = client.srandmember(normalize_key(key), value)
      metatransform(value)
    end

    def value?(key, value)
      client.sismember(normalize_key(key), value)
    end

    def count(key)
      client.scard(normalize_key(key))
    end

    def create(key, *args)
      client.sadd(normalize_key(key), args)
    end

    def create_combination(key, *args)
      client.sunionstore(normalize_key(key), args)
    end

    def create_difference(key, *args)
      client.sdiffstore(normalize_key(key), *args)
    end

    def create_intersection(key, *args)
      client.sinterstore(normalize_key(key), args)
    end

    def move(key, destination, value)
      client.smove(normalize_key(key), destination.to_s, value)
    end

    def destroy(key, *args)
      client.srem(normalize_key(key), *args)
    end

    def destroy_random(key)
      client.spop(normalize_key(key))
    end

    def scan(key, cursor, opts = {})
      client.sscan(normalize_key(key), cursor, opts)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_redis_db-1.1.0 lib/active_redis_db/set.rb
active_redis_db-1.0.2 lib/active_redis_db/set.rb
active_redis_db-1.0.1 lib/active_redis_db/set.rb
active_redis_db-1.0.0 lib/active_redis_db/set.rb