Metadata-Version: 1.1
Name: saferedisqueue
Version: 1.0.0
Summary: A small wrapper around Redis that provides access to a FIFO queue.
Home-page: https://github.com/hellp/saferedisqueue
Author: Fabian Neumann, ferret go GmbH
Author-email: neumann@ferret-go.com
License: Copyright (c) 2013, Fabian Neumann, ferret go GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in the
      documentation and/or other materials provided with the distribution.

    * Neither the name of the ferret go GmbH nor the names of its contributors
      may be used to endorse or promote products derived from this software
      without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Description: ==============
        saferedisqueue
        ==============
        
        A small wrapper around `Redis <http://www.redis.io>`_ (using the "standard"
        `Python redis client lib <https://pypi.python.org/pypi/redis>`_) that provides
        access to a FIFO queue and allows upstream code to mark pop'ed items as
        processed successfully (ACK'ing) or unsucessfully (FAIL'ing).
        
        Failed items are automatically requeued. Addionally a backup is kept for items
        that were neither ack'ed nor fail'ed, i.e. in case the consumer crashes. The
        backup items will be requeued as soon as one of the consumer(s) comes up
        again.
        
        All actions are atomic and it is safe to have multiple producers and consumers
        accessing the same queue concurrently.
        
        .. attention:: Currently it only works with Redis 2.4. The code should be easy
                       to adapt to 2.6 — pull requests and patches accepted ;-)
        
        
        Usage as a library
        ==================
        
        >>> queue = SafeRedisQueue(name='test')
        >>> queue.push("Hello World")
        >>> queue.push("Foo bar")
        >>> queue.pop()
        ('595d43b2-2e49-4e96-a1d2-0848d1c7f0d3', 'Hello World')
        >>> queue.pop()
        ('1df060eb-b578-499d-bede-20db9da8184e', 'Foo bar')
        
        
        ACK'ing and FAIL'ing
        --------------------
        
        >>> queue.push("Good stuff")
        >>> queue.push("Bad stuff")
        >>> uid_good, payload_good = queue.pop()
        >>> uid_bad, payload_bad = queue.pop()
        ...
        # process the payloads...
        ...
        >>> queue.ack(uid_good)  # done with that one
        >>> queue.fail(uid_bad)  # something didn't work out with that one, let's requeue
        >>> uid, payload = queue.pop()  # pop again; we get the requeued payload again
        >>> uid == uid_bad
        True
        ...
        # try again
        ...
        >>> queue.ack(uid)  # now it worked; ACK the stuff now
        
        
        pop timeout
        -----------
        
        `SafeRedisQueue.pop` accepts a timeout parameter:
        
        - 0 (the default) blocks forever, waiting for items
        - a positive number blocks that amount of seconds
        - a negative timeout disables blocking
        
        
        Constructor parameters
        ----------------------
        
        `SafeRedisQueue` accepts ``*args, **kwargs`` and passes them to
        `redis.StrictRedis`, so use whatever you need.
        
        *Two exceptions*, use these in the keyword arguments to configure `SafeRedisQueue` itself:
        
        `name`
            A prefix used for the keys in Redis. Default: "0", which creates the
            following keys in your Redis DB:
        
            - srq:0:items
            - srq:0:queue
            - srq:0:ackbuf
            - srq:0:backup
            - srq:0:backuplock
        
        `autoclean_interval`
            An interval in seconds (default: 60) at which *unacknowledged* items are
            requeued automatically. (They are moved from the internal ackbuf and backup data
            structures to the queue again.)
        
            Pass ``None`` to disable autocleaning. It's enabled by default!
        
        
        Command line usage
        ==================
        
        For quick'n'dirty testing, you can use the script from the command line to put stuff into the queue::
        
            $ echo "Hello World" | python saferedisqueue.py producer
        
        ...and get it out again::
        
            $ python saferedisqueue.py consumer
            cbdabbc8-1c0f-4eb0-8733-fdb62a9c0fa6 Hello World
        
        
        =======
        Changes
        =======
        
        1.0.0 - 2013-06-05
        ------------------
        
        - Released as open-source under 3-clause BSD license. Code identical to 0.3.0.
        
        
        0.3.0 - 2012-05-22
        ------------------
        
        - The constructor now accepts an "autoclean_interval" value to set the interval
          at which the ackbuf -> backup rotation and backup requeuing happens.
          Setting the value to `None` disables autoclean completely.
          Default: 60 (seconds).
        
        
        0.2.2 - 2012-03-29
        ------------------
        
        - Negative timeout makes .pop() non-blocking.
        
        
        0.2.1 - 2012-03-09
        ------------------
        
        - Added setup.py and publish it on our internal package directory.
        
        
        0.2.0 - 2012-03-08
        ------------------
        
        - Renamed methods ("push_item" -> "push" etc.)
        - New autoclean method that is called on every .pop()
        - Internal: New names for keys in the redis db.
        
Keywords: Redis,key-value store,queue,queueing,Storm
Platform: UNKNOWN
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7
Classifier: Topic :: Internet
