Sha256: 3de60d4e3d30bddc704b7631ce39e0b398276d5ba6761a29d980a28a837b17cb

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 KB

Contents

module Picky

  module Backends

    class Redis

      module DirectlyManipulable

        attr_accessor :backend, :key

        def self.make backend, list, key
          list.extend DirectlyManipulable
          list.backend = backend
          list.key     = key
        end

        # THINK Current implementation is very brittle.
        #
        @@append_index = 0
        def << value
          super
          zadd value, @@append_index+=1
        end

        # THINK Current implementation is very brittle.
        #
        @@unshift_index = 0
        def unshift value
          super
          zadd value, @@unshift_index -= 1
        end
        
        # Deletes the value.
        #
        def delete value
          result = super value
          backend.client.zrem "#{backend.namespace}:#{key}", value if result
          result
        end
        
        # Z-Adds a value with the given index.
        #
        def zadd value, index
          backend.client.zadd "#{backend.namespace}:#{key}", index, value
          backend[key]
        end
        
      end

    end

  end

end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
picky-4.12.8 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.7 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.6 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.5 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.4 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.3 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.2 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.1 lib/picky/backends/redis/directly_manipulable.rb
picky-4.12.0 lib/picky/backends/redis/directly_manipulable.rb
picky-4.11.3 lib/picky/backends/redis/directly_manipulable.rb
picky-4.11.2 lib/picky/backends/redis/directly_manipulable.rb
picky-4.11.1 lib/picky/backends/redis/directly_manipulable.rb
picky-4.11.0 lib/picky/backends/redis/directly_manipulable.rb
picky-4.10.0 lib/picky/backends/redis/directly_manipulable.rb
picky-4.9.0 lib/picky/backends/redis/directly_manipulable.rb
picky-4.8.1 lib/picky/backends/redis/directly_manipulable.rb
picky-4.8.0 lib/picky/backends/redis/directly_manipulable.rb
picky-4.7.0 lib/picky/backends/redis/directly_manipulable.rb
picky-4.6.6 lib/picky/backends/redis/directly_manipulable.rb
picky-4.6.5 lib/picky/backends/redis/directly_manipulable.rb