Skip to main content

Opinionated Python toolbox

Project description

Opinionated Python toolbox

List of Tools

  1. Redis backed techies.landmines.Queue, (almost) Python standard Queue compatible, the main difference is that it’s semi-persisted in Redis.

  2. Redis backed techies.landmines.UniQueue, a Queue implementation that keeps only distinct items.

Prerequisites

  • Redis server

Installation

$ pip install techies
$ pip install techies --upgrade  # to update

Usage

Queue

from techies.landmines import Queue

q = Queue(key='demo_q', host='localhost', port=6379, db=0)

# put, or enqueue
print(q.put('lol'))  # 1L
print(q.put('dota'))  # 2L
print(q.put('skyrim'))  # 3L
print(q.put('dota'))  # 4L
# Queue.put returns the queue size at that moment

# Check size of the queue, two ways
print(q.qsize())  # 4
print(len(q))  # 4

# get, or dequeue
print(q.get())  # 'lol'
print(q.get())  # 'dota'
print(q.get())  # 'skyrim'
print(q.get())  # 'dota'
print(q.get())  # NoneType

# clear the queue
q.clear()

UniQueue

from techies.landmines import UniQueue

q = UniQueue(key='demo_q', host='localhost', port=6379, db=0)

# put, or enqueue
print(q.put('lol'))  # 1
print(q.put('dota'))  # 1
print(q.put('skyrim'))  # 1
print(q.put('dota'))  # 0
# UniQueue.put returns 1 on success, 0 otherwise; such as duplicated item

# Check size of the unique queue, two ways
print(q.qsize())  # 3
print(len(q))  # 3

# get, or dequeue
print(q.get())  # 'lol'
print(q.get())  # 'dota'
print(q.get())  # 'skyrim'
print(q.get())  # NoneType
print(q.get())  # NoneType

# clear the queue
q.clear()

Test (Unit Tests)

To run unit tests locally, make sure that you have Redis server installed and running

$ pip install -r requirements.txt
$ pip install -r test_requirements.txt
$ nosetests --with-coverage --cover-package=techies

License

The MIT License (MIT). See the full LICENSE.

Changelog

0.1.0 (2014-01-16)

  • Initial release with Redis backed Queue and UniQueue

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

techies-0.1.1.tar.gz (5.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page