Sha256: 64fbd012d4241163c351c7acb7cce0f592f21f742dd8e45b007b592ee3da44e7

Contents?: true

Size: 1.95 KB

Versions: 7

Compression:

Stored size: 1.95 KB

Contents

module Picky

  module Backend

    class Redis

      # Redis Backend Accessor.
      #
      # Provides necessary helper methods for its
      # subclasses.
      # Not directly useable, as it does not provide
      # dump/load methods.
      #
      class Basic

        attr_reader :namespace, :backend

        # An index cache takes a path, without file extension,
        # which will be provided by the subclasses.
        #
        def initialize namespace
          @namespace = namespace

          # TODO Turn this inside out such that people can pass in
          # their own Redis instance.
          #
          # TODO Make the :db a real option.
          #
          @backend = ::Redis.new :db => 15
        end

        # Does nothing.
        #
        def load
          # Nothing.
        end
        # We do not use Redis to retrieve data.
        #
        def retrieve
          # Nothing.
        end

        # Redis does not backup.
        #
        def backup
          # Nothing.
        end

        # Deletes the Redis index namespace.
        #
        def delete
          # Not implemented here.
          # Note: backend.flushdb might be the way to go,
          #       but since we cannot delete by key pattern,
          #       we don't do anything.
        end

        # Checks.
        #

        # Is this cache suspiciously small?
        #
        def cache_small?
          size < 1
        end

        # Is the cache ok?
        #
        # A small cache is still ok.
        #
        def cache_ok?
          size > 0
        end

        # Extracts the size of the file in Bytes.
        #
        # Note: This is a very forgiving implementation.
        #       But as long as Redis does not implement
        #       DBSIZE KEYPATTERN, we are stuck with this.
        #
        def size
          backend.dbsize
        end

        #
        #
        def to_s
          "#{self.class}(#{namespace}:*)"
        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/basic.rb
picky-3.0.0 lib/picky/backend/redis/basic.rb
picky-3.0.0.pre5 lib/picky/backend/redis/basic.rb
picky-3.0.0.pre4 lib/picky/backend/redis/basic.rb
picky-3.0.0.pre3 lib/picky/backend/redis/basic.rb
picky-3.0.0.pre2 lib/picky/backend/redis/basic.rb
picky-3.0.0.pre1 lib/picky/backend/redis/basic.rb