Sha256: 3d0b3ea59485547e7bd8feed0bc9ff3b7766aa90cfabcb0221cd0c833b88eecc

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

module Backend

  class Redis

    class ListHash < Basic

      # Writes the hash into Redis.
      #
      def dump hash
        clear
        hash.each_pair do |key, values|
          redis_key = "#{namespace}:#{key}"
          i = 0
          values.each do |value|
            i += 1
            backend.zadd redis_key, i, value
          end
        end
      end

      # Clear the index for this list.
      #
      # Note: Perhaps we can use a server only command.
      #       This is not the optimal way to do it.
      #
      def clear
        redis_key = "#{namespace}:*"
        backend.keys(redis_key).each do |key|
          backend.del key
        end
      end

      # Get a collection.
      #
      def collection key
        backend.zrange "#{namespace}:#{key}", 0, -1
      end

      # Get a single value.
      #
      def member key
        raise "Can't retrieve single value :#{key} from a Redis ListHash. Use Index::Redis::StringHash."
      end

    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
picky-2.7.0 lib/picky/backend/redis/list_hash.rb