Sha256: 12155506d0e68fa5963611d8c82aa5d04b4595d90d5f3c51646beb56030721f6

Contents?: true

Size: 1.07 KB

Versions: 7

Compression:

Stored size: 1.07 KB

Contents

module Picky

  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 Indexes::Redis::StringHash."
        end

      end

    end

  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
picky-3.0.1 lib/picky/backend/redis/list_hash.rb
picky-3.0.0 lib/picky/backend/redis/list_hash.rb
picky-3.0.0.pre5 lib/picky/backend/redis/list_hash.rb
picky-3.0.0.pre4 lib/picky/backend/redis/list_hash.rb
picky-3.0.0.pre3 lib/picky/backend/redis/list_hash.rb
picky-3.0.0.pre2 lib/picky/backend/redis/list_hash.rb
picky-3.0.0.pre1 lib/picky/backend/redis/list_hash.rb