godis

package module
v0.0.0-...-cab1865 Latest Latest
Warning

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

Go to latest
Published: May 6, 2012 License: BSD-3-Clause Imports: 8 Imported by: 6

README

exp-godis

exp-godis - an experimental Redis client for Go. It supports commands and features through a simple API which aims to be is easy to use.

  1. Package docs
  2. Source code

Install exp-godis

exp-godis is available at github.com. Get it by running.

$ go get github.com/simonz05/exp-godis

Importing exp-godis to your code can be done with import "github.com/simonz05/exp-godis". Thats it!

Use exp-godis

A few examples are included. The following demonstrates SET and GET. See example/ for more.

package main

import (
    "github.com/simonz05/exp-godis"
)

func main() {
    c := godis.NewClient("tcp:127.0.0.1:6379")

    res, err := c.Call("SET", "foo", "bar")

    if err != nil {
        println(err.Error())
        return
    }

    res, _ = c.Call("GET", "foo")
    println("GET foo:", res.Elem.String())
}

Build and run the example.

$ make string; ./string

You should see the following printed in the terminal.

GET foo: bar 

In case your redis server isn't running, you'll get an error.

ERR 127.0.0.1:6379

Documentation

Overview

package godis implements a db client for Redis.

Index

Constants

View Source
const IOBUFLEN = 1024

Variables

View Source
var (
	ErrFullBuf  = errors.New("Full buffer")
	ErrNotFound = errors.New("Not found")
)
View Source
var ConnSum = 0
View Source
var (
	ErrProtocol = errors.New("godis: protocol error")
)
View Source
var MaxConnections = 50

Functions

This section is empty.

Types

type AsyncClient

type AsyncClient struct {
	*Client
	// contains filtered or unexported fields
}

func NewAsyncClient

func NewAsyncClient(addr string) *AsyncClient

func (*AsyncClient) Call

func (ac *AsyncClient) Call(args ...interface{}) (err error)

func (*AsyncClient) Close

func (ac *AsyncClient) Close()

func (*AsyncClient) Poll

func (ac *AsyncClient) Poll() (*Reply, error)

type Client

type Client struct {
	Addr  string
	Proto string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(addr string) *Client

func (*Client) AsyncClient

func (c *Client) AsyncClient() *AsyncClient

func (*Client) Call

func (c *Client) Call(args ...interface{}) (*Reply, error)

func (*Client) Connect

func (c *Client) Connect() (conn Connection, err error)

pop a connection from pool

func (*Client) Push

func (c *Client) Push(conn Connection)

return connection to pool

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

func NewConn

func NewConn(addr, proto string) (*Conn, error)

New connection

func (*Conn) Close

func (c *Conn) Close() error

close socket connection

func (*Conn) Read

func (c *Conn) Read() (*Reply, error)

read and parse a reply from socket

func (*Conn) Sock

func (c *Conn) Sock() net.Conn

returns the net.Conn for the struct

func (*Conn) Write

func (c *Conn) Write(args ...interface{}) error

write args to socket

type Connection

type Connection interface {
	Write(args ...interface{}) error
	Read() (*Reply, error)
	Close() error
	Sock() net.Conn
}

type Elem

type Elem []byte

func (Elem) Bool

func (e Elem) Bool() bool

func (Elem) Bytes

func (e Elem) Bytes() []byte

func (Elem) Float64

func (e Elem) Float64() float64

func (Elem) Int

func (e Elem) Int() int

func (Elem) Int64

func (e Elem) Int64() int64

func (Elem) String

func (e Elem) String() string

type Message

type Message struct {
	Channel string
	Elem    Elem
}

type Reply

type Reply struct {
	Err   error
	Elem  Elem
	Elems []*Reply
}

func Parse

func Parse(buf *reader) *Reply

func (*Reply) BytesArray

func (r *Reply) BytesArray() [][]byte

func (*Reply) Hash

func (r *Reply) Hash() map[string]Elem

func (*Reply) IntArray

func (r *Reply) IntArray() []int64

func (*Reply) Len

func (r *Reply) Len() int

func (*Reply) Message

func (r *Reply) Message() *Message

func (*Reply) StringArray

func (r *Reply) StringArray() []string

func (*Reply) StringMap

func (r *Reply) StringMap() map[string]string

Directories

Path Synopsis
misc
net

Jump to

Keyboard shortcuts

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