redis-queue

module
v0.0.0-...-c2fae12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2015 License: Apache-2.0

README

redis-queue Circle CI

A Go implementation of a FIFO queue backed by Redis

Installation

Install redis-queue using the "go get" command:

go get github.com/skidder/redis-queue/rq

The Go distribution and Redigo (a Go client for Redis) are the only dependencies.

Samples

Single-Queue Client

package main

import "flag"
import "fmt"
import "log"
import "github.com/skidder/redis-queue/rq"

var (
	redisServer = flag.String("redisServer", ":6379", "Hostname and port for the Redis server")
	redisPassword = flag.String("redisPassword", "", "Password, optional")
)

func main() {
	flag.Parse();

	fmt.Printf("redisServer: %s\n", *redisServer)
	fmt.Printf("redisPassword: %s\n", *redisPassword)

	pool := rq.newPool(":6379")
	defer pool.Close()

	queue_name := "example"
	q, err := rq.QueueConnect(pool, queue_name)
	if err != nil {
		log.Fatal(err)
	}

 	// push a simple value to the queue
	q.Push("bar")
	for {
		// print queue length
		length, err := q.Length()
		fmt.Printf("%s: length: %d\n", queue_name, length)

		// remove an item from the queue
		rep, err := q.Pop(0)
		if err != nil {
			log.Println(err)
			log.Fatalf("Uh no!")
		}
		fmt.Printf("%s: message: %s\n", queue_name, rep)
	}
}

Multi-Queue Client

package main

import "fmt"
import "log"
import "github.com/skidder/redis-queue/rq"

func main() {
	pool1 := rq.newPool(":7777")
	defer pool1.Close()

	pool2 := rq.newPool(":8777")
	defer pool2.Close()

	queue_name := "example"
	q, err := rq.MultiQueueConnect([]redis.Pool{*pool1, *pool2}, queue_name)
	if error != nil {
		log.Fatal(error)
	}

	// push a simple value to the queue
	q.Push("bar")
	for {
		// print queue length
		length  := q.Length()
		fmt.Printf("%s: length: %d\n", queue_name, length)

		// remove an item from the queue
		rep, _ := q.Pop(1)
		if rep != "" {
			fmt.Printf("Received message: %s\n", rep)
		} else {
			fmt.Printf("Queue is empty\n")
		}
	}
}

License

redis-queue is available under the Apache License, Version 2.0.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/garyburd/redigo/internal/redistest
Package redistest contains utilities for writing Redigo tests.
Package redistest contains utilities for writing Redigo tests.
_workspace/src/github.com/garyburd/redigo/redis
Package redis is a client for the Redis database.
Package redis is a client for the Redis database.
Package rq provides a simple queue abstraction that is backed by Redis.
Package rq provides a simple queue abstraction that is backed by Redis.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL