ryz310/redis-objects-periodical

View on GitHub
lib/redis/base_set_object.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

class Redis
  module BaseSetObject
    private

    def get_redis_object(key)
      Redis::Set.new(key)
    end

    def get_value_from_redis(key)
      vals = redis.smembers(key)
      vals.nil? ? [] : vals.map { |v| unmarshal(v) }
    end

    def get_values_from_redis(keys)
      redis.sunion(*keys).map { |v| unmarshal(v) }
    end

    def delete_from_redis(key)
      redis.del(key)
    end

    def empty_value
      []
    end
  end
end