redis

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

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

Go to latest
Published: Jul 30, 2016 License: MIT Imports: 10 Imported by: 77

README

redis.go

redis.go is a client for the redis key-value store.

Some features include:

  • Designed for Redis 2.6.x.
  • Support for all redis types - strings, lists, sets, sorted sets, and hashes
  • Very simple usage
  • Connection pooling ( with configurable size )
  • Support for concurrent access
  • Manages connections to the redis server, including dropped and timed out connections
  • Marshaling/Unmarshaling go types to hashes

This library is stable and is used in production environments. However, some commands have not been tested as thoroughly as others. If you find any bugs please file an issue!

Installation

Just run go get github.com/hoisie/redis

Examples

Most of the examples connect to a redis database running in the default port -- 6379.

Hello World example

package main

import "github.com/hoisie/redis"

func main() {
    var client redis.Client
    var key = "hello"
    client.Set(key, []byte("world"))
    val, _ := client.Get("hello")
    println(key, string(val))
}

Strings

var client redis.Client
client.Set("a", []byte("hello"))
val, _ := client.Get("a")
println(string(val))
client.Del("a")

Lists

var client redis.Client
vals := []string{"a", "b", "c", "d", "e"}
for _, v := range vals {
    client.Rpush("l", []byte(v))
}
dbvals,_ := client.Lrange("l", 0, 4)
for i, v := range dbvals {
    println(i,":",string(v))
}
client.Del("l")

Publish/Subscribe

sub := make(chan string, 1)
sub <- "foo"
messages := make(chan Message, 0)
go client.Subscribe(sub, nil, nil, nil, messages)

time.Sleep(10 * 1000 * 1000)
client.Publish("foo", []byte("bar"))

msg := <-messages
println("received from:", msg.Channel, " message:", string(msg.Message))

close(sub)
close(messages)

More examples coming soon. See redis_test.go for more usage examples.

Commands not supported yet

  • MULTI/EXEC/DISCARD/WATCH/UNWATCH
  • SORT
  • ZUNIONSTORE / ZINTERSTORE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Addr        string
	Db          int
	Password    string
	MaxPoolSize int
	// contains filtered or unexported fields
}

func (*Client) Append

func (client *Client) Append(key string, val []byte) error

func (*Client) Auth

func (client *Client) Auth(password string) error

func (*Client) Bgrewriteaof

func (client *Client) Bgrewriteaof() error

func (*Client) Bgsave

func (client *Client) Bgsave() error

func (*Client) Blpop

func (client *Client) Blpop(keys []string, timeoutSecs uint) (*string, []byte, error)

func (*Client) Brpop

func (client *Client) Brpop(keys []string, timeoutSecs uint) (*string, []byte, error)

func (*Client) Dbsize

func (client *Client) Dbsize() (int, error)

func (*Client) Decr

func (client *Client) Decr(key string) (int64, error)

func (*Client) Decrby

func (client *Client) Decrby(key string, val int64) (int64, error)

func (*Client) Del

func (client *Client) Del(key string) (bool, error)

func (*Client) Exists

func (client *Client) Exists(key string) (bool, error)

func (*Client) Expire

func (client *Client) Expire(key string, time int64) (bool, error)

func (*Client) Flush

func (client *Client) Flush(all bool) error

func (*Client) Get

func (client *Client) Get(key string) ([]byte, error)

func (*Client) Getset

func (client *Client) Getset(key string, val []byte) ([]byte, error)

func (*Client) Hdel

func (client *Client) Hdel(key string, field string) (bool, error)

func (*Client) Hexists

func (client *Client) Hexists(key string, field string) (bool, error)

func (*Client) Hget

func (client *Client) Hget(key string, field string) ([]byte, error)

func (*Client) Hgetall

func (client *Client) Hgetall(key string, val interface{}) error

func (*Client) Hincrby

func (client *Client) Hincrby(key string, field string, val int64) (int64, error)

func (*Client) Hkeys

func (client *Client) Hkeys(key string) ([]string, error)

func (*Client) Hlen

func (client *Client) Hlen(key string) (int, error)

func (*Client) Hmget

func (client *Client) Hmget(key string, fields ...string) ([][]byte, error)

func (*Client) Hmset

func (client *Client) Hmset(key string, mapping interface{}) error

func (*Client) Hset

func (client *Client) Hset(key string, field string, val []byte) (bool, error)

func (*Client) Hvals

func (client *Client) Hvals(key string) ([][]byte, error)

func (*Client) Incr

func (client *Client) Incr(key string) (int64, error)

func (*Client) Incrby

func (client *Client) Incrby(key string, val int64) (int64, error)

func (*Client) Keys

func (client *Client) Keys(pattern string) ([]string, error)

func (*Client) Lastsave

func (client *Client) Lastsave() (int64, error)

func (*Client) Lindex

func (client *Client) Lindex(key string, index int) ([]byte, error)

func (*Client) Llen

func (client *Client) Llen(key string) (int, error)

func (*Client) Lpop

func (client *Client) Lpop(key string) ([]byte, error)

func (*Client) Lpush

func (client *Client) Lpush(key string, val []byte) error

func (*Client) Lrange

func (client *Client) Lrange(key string, start int, end int) ([][]byte, error)

func (*Client) Lrem

func (client *Client) Lrem(key string, count int, value []byte) (int, error)

func (*Client) Lset

func (client *Client) Lset(key string, index int, value []byte) error

func (*Client) Ltrim

func (client *Client) Ltrim(key string, start int, end int) error

func (*Client) Mget

func (client *Client) Mget(keys ...string) ([][]byte, error)

func (*Client) Move

func (client *Client) Move(key string, dbnum int) (bool, error)

func (*Client) Mset

func (client *Client) Mset(mapping map[string][]byte) error

func (*Client) Msetnx

func (client *Client) Msetnx(mapping map[string][]byte) (bool, error)

func (*Client) Publish

func (client *Client) Publish(channel string, val []byte) error

Publish a message to a redis server.

func (*Client) Randomkey

func (client *Client) Randomkey() (string, error)

func (*Client) Rename

func (client *Client) Rename(src string, dst string) error

func (*Client) Renamenx

func (client *Client) Renamenx(src string, dst string) (bool, error)

func (*Client) Rpop

func (client *Client) Rpop(key string) ([]byte, error)

func (*Client) Rpoplpush

func (client *Client) Rpoplpush(src string, dst string) ([]byte, error)

func (*Client) Rpush

func (client *Client) Rpush(key string, val []byte) error

func (*Client) Sadd

func (client *Client) Sadd(key string, value []byte) (bool, error)

func (*Client) Save

func (client *Client) Save() error

func (*Client) Scard

func (client *Client) Scard(key string) (int, error)

func (*Client) Sdiff

func (client *Client) Sdiff(key1 string, keys []string) ([][]byte, error)

func (*Client) Sdiffstore

func (client *Client) Sdiffstore(dst string, key1 string, keys []string) (int, error)

func (*Client) Set

func (client *Client) Set(key string, val []byte) error

func (*Client) Setex

func (client *Client) Setex(key string, time int64, val []byte) error

func (*Client) Setnx

func (client *Client) Setnx(key string, val []byte) (bool, error)

func (*Client) Sinter

func (client *Client) Sinter(keys ...string) ([][]byte, error)

func (*Client) Sinterstore

func (client *Client) Sinterstore(dst string, keys ...string) (int, error)

func (*Client) Sismember

func (client *Client) Sismember(key string, value []byte) (bool, error)

func (*Client) Smembers

func (client *Client) Smembers(key string) ([][]byte, error)

func (*Client) Smove

func (client *Client) Smove(src string, dst string, val []byte) (bool, error)

func (*Client) Spop

func (client *Client) Spop(key string) ([]byte, error)

func (*Client) Srandmember

func (client *Client) Srandmember(key string) ([]byte, error)

func (*Client) Srem

func (client *Client) Srem(key string, value []byte) (bool, error)

func (*Client) Strlen

func (client *Client) Strlen(key string) (int, error)

func (*Client) Subscribe

func (client *Client) Subscribe(subscribe <-chan string, unsubscribe <-chan string, psubscribe <-chan string, punsubscribe <-chan string, messages chan<- Message) error

Subscribe to redis serve channels, this method will block until one of the sub/unsub channels are closed. There are two pairs of channels subscribe/unsubscribe & psubscribe/punsubscribe. The former does an exact match on the channel, the later uses glob patterns on the redis channels. Closing either of these channels will unblock this method call. Messages that are received are sent down the messages channel.

func (*Client) Substr

func (client *Client) Substr(key string, start int, end int) ([]byte, error)

func (*Client) Sunion

func (client *Client) Sunion(keys ...string) ([][]byte, error)

func (*Client) Sunionstore

func (client *Client) Sunionstore(dst string, keys ...string) (int, error)

func (*Client) Ttl

func (client *Client) Ttl(key string) (int64, error)

func (*Client) Type

func (client *Client) Type(key string) (string, error)

func (*Client) Zadd

func (client *Client) Zadd(key string, value []byte, score float64) (bool, error)

func (*Client) Zcard

func (client *Client) Zcard(key string) (int, error)

func (*Client) Zcount

func (client *Client) Zcount(key string, min float64, max float64) (int, error)

func (*Client) ZcountAll

func (client *Client) ZcountAll(key string) (int, error)

func (*Client) Zincrby

func (client *Client) Zincrby(key string, value []byte, score float64) (float64, error)

func (*Client) Zrange

func (client *Client) Zrange(key string, start int, end int) ([][]byte, error)

func (*Client) Zrangebyscore

func (client *Client) Zrangebyscore(key string, start float64, end float64) ([][]byte, error)

func (*Client) Zrank

func (client *Client) Zrank(key string, value []byte) (int, error)

func (*Client) Zrem

func (client *Client) Zrem(key string, value []byte) (bool, error)

func (*Client) Zremrangebyrank

func (client *Client) Zremrangebyrank(key string, start int, end int) (int, error)

func (*Client) Zremrangebyscore

func (client *Client) Zremrangebyscore(key string, start float64, end float64) (int, error)

func (*Client) Zrevrange

func (client *Client) Zrevrange(key string, start int, end int) ([][]byte, error)

func (*Client) Zrevrank

func (client *Client) Zrevrank(key string, value []byte) (int, error)

func (*Client) Zscore

func (client *Client) Zscore(key string, member []byte) (float64, error)

type Message

type Message struct {
	ChannelMatched string
	Channel        string
	Message        []byte
}

Container for messages received from publishers on channels that we're subscribed to.

type RedisError

type RedisError string

func (RedisError) Error

func (err RedisError) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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