wredis

package module
v0.0.0-...-880f5e4 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2016 License: Apache-2.0 Imports: 4 Imported by: 0

README

Wredis Build Status Go Report Card Coverage Status GoDoc

Wredis is a wrapper around the redigo redis.Pool and provides an easy-to-use API for Redis commands

Getting Started

Go Get
go get github.com/crowdriff/wredis
Usage

API Reference

import (
	"log"

	"github.com/crowdriff/wredis"
)

var w *wredis.Wredis

func main() {
	var err error
	if w, err = wredis.NewDefaultPool(); err != nil {
		log.Fatal(err.Error())
	}
	defer w.Close()

	if err = w.Set("mykey", "myval"); err != nil {
		log.Fatal(err.Error())
	}

	val, err := w.Get("mykey")
	if err != nil {
		log.Fatal(err.Error())
	}

	log.Println(val)
}
Implemented Commands
  • Connection
    • Select: switch the redis database
  • Keys
    • Del: delete a key
    • Exists: does a key exist
    • Expire: set an expiry time for a key
    • Keys: fetch a list of keys that match the given pattern
    • Rename: rename a key
  • Server
    • FlushAll: Flush the contents of the redis server (requires unsafe Wredis)
    • FlushDb: Flush the contents of a specific redis db (requires unsafe Wredis)
  • Sets
    • SAdd: add members to a set
    • SCard: count of a set
    • SDiffStore: perform a diff and store the results in redis
    • SMembers: return the members of a set
    • SUnionStore: perform a union and store the results in redis
  • Strings
    • Get: get a key's value
    • Incr: increment a key's value by 1
    • Set: set a key's value
    • SetEx: set a key's value with an expiry in seconds
Convenience methods
  • Keys
    • DelWithPattern: delete all keys matching a pattern
  • Server
    • SelectAndFlushDb: selects a db before flushing it
  • Strings
    • SetExDuration: set a string with an expiry using a time.Duration

Contributing

Install Tools and Dependencies
make tools
make deps
Contribute
  1. Fork
  2. Make changes
  3. Add tests
  4. Run make test
  5. Send a PR

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Wredis

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

Wredis is a struct wrapper around the redis.Pool that implements Redis commands (http://redis.io/commands)

func NewDefaultPool

func NewDefaultPool() (*Wredis, error)

NewDefaultPool returns a redis.Pool with a localhost:6379 address and db set to 0.

func NewPool

func NewPool(host string, port, db uint) (*Wredis, error)

NewPool creates a redis pool connected to the given host:port and db.

func NewUnsafe

func NewUnsafe(host string, port, db uint) (*Wredis, error)

NewUnsafe returns an unsafe wrapper around the redigo Pool. The lack of safety allows usage of certain methods that could be harmful if accidentally invoked in production (e.g. FlushAll)

func (*Wredis) Close

func (w *Wredis) Close() error

Close closes the pool connection

func (*Wredis) Del

func (w *Wredis) Del(keys ...string) (int64, error)

Del deletes one or more keys from Redis and returns a count of how many keys were actually deleted. See http://redis.io/commands/del

func (*Wredis) DelWithPattern

func (w *Wredis) DelWithPattern(pattern string) (int64, error)

DelWithPattern is a convenience method that Deletes all keys matching the pattern

func (*Wredis) ExecBool

func (w *Wredis) ExecBool(f func(redis.Conn) (bool, error)) (bool, error)

ExecBool is a helper function to execute any series of commands on a redis.Conn that returns a bool response

func (*Wredis) ExecInt64

func (w *Wredis) ExecInt64(f func(redis.Conn) (int64, error)) (int64, error)

ExecInt64 is a helper function to execute any series of commands on a redis.Conn that return an int64 response

func (*Wredis) ExecString

func (w *Wredis) ExecString(f func(redis.Conn) (string, error)) (string, error)

ExecString is a helper function to execute any series of commands on a redis.Conn that return a string response

func (*Wredis) ExecStrings

func (w *Wredis) ExecStrings(f func(redis.Conn) ([]string, error)) ([]string, error)

ExecStrings is a helper function to execute any series of commands on a redis.Conn that return a string slice response

func (*Wredis) Exists

func (w *Wredis) Exists(key string) (bool, error)

Exists checks for the existence of `key` in Redis. Note however, even though a variable number of keys can be passed to the EXISTS command since Redis 3.0.3, we will restrict this to a single key in order to be able to return an absolute response regarding existence. See http://redis.io/commands/exists

func (*Wredis) Expire

func (w *Wredis) Expire(key string, seconds int) (bool, error)

Expire sets a timeout of "seconds" on "key". If an error is encountered, it is returned. If the key doesn't exist or the timeout couldn't be set, `false, nil` is returned. On success, `true, nil` is returned. See http://redis.io/commands/expire

func (*Wredis) FlushAll

func (w *Wredis) FlushAll() error

FlushAll deletes all the keys from all the db's on the Redis server. This is a very dangerous method to use in production. See http://redis.io/commands/flushall

func (*Wredis) FlushDb

func (w *Wredis) FlushDb() error

FlushDb deletes all the keys from the currently selected database See http://redis.io/commands/flushdb

func (*Wredis) Get

func (w *Wredis) Get(key string) (string, error)

Get fetches a key's string value. See http://redis.io/commands/get

func (*Wredis) Incr

func (w *Wredis) Incr(key string) (int64, error)

Incr increments the number stored at key by one. See http://redis.io/commands/incr

func (*Wredis) Keys

func (w *Wredis) Keys(pattern string) ([]string, error)

Keys takes a pattern and returns any/all keys matching the pattern. See http://redis.io/commands/keys

func (*Wredis) LLen

func (w *Wredis) LLen(key string) (int64, error)

LLen returns the length of the list stored at key. For more information, see http://redis.io/commands/llen.

func (*Wredis) LPush

func (w *Wredis) LPush(key string, items ...string) (int64, error)

LPush inserts the provided item(s) at the head of the list stored at key. For more information, see http://redis.io/commands/lpush.

func (*Wredis) MGet

func (w *Wredis) MGet(keys []string) ([]string, error)

MGet returns the values of all provided keys. For a key that does not exist, an empty string is returned. See http://redis.io/commands/mget.

func (*Wredis) RPop

func (w *Wredis) RPop(key string) (string, error)

RPop removes and returns the last element of the list stored at key. For more information, see http://redis.io/commands/rpop.

func (*Wredis) Rename

func (w *Wredis) Rename(key, newKey string) error

Rename will rename `key` to `newKey`. They must not be empty or identical. See `http://redis.io/commands/rename`

func (*Wredis) SAdd

func (w *Wredis) SAdd(dest string, members []string) (int64, error)

SAdd implements the SADD command. It adds the `members` into the set `dest`. An error is returned if `members` is nil or empty, otherwise it returns the number of members added. See http://redis.io/commands/sadd

func (*Wredis) SCard

func (w *Wredis) SCard(key string) (int64, error)

SCard returns the cardinality of the set `key`. See http://redis.io/commands/scard

func (*Wredis) SDiffStore

func (w *Wredis) SDiffStore(dest string, sets ...string) (int64, error)

SDiffStore executes the SDIFFSTORE command. See `http://redis.io/commands/sdiffstore`

func (*Wredis) SMembers

func (w *Wredis) SMembers(key string) ([]string, error)

SMembers returns the members of the set denoted by `key`. See http://redis.io/commands/smembers

func (*Wredis) SUnionStore

func (w *Wredis) SUnionStore(dest string, sets ...string) (int64, error)

SUnionStore implements the SUNIONSTORE command. See `http://redis.io/commands/sunionstore`

func (*Wredis) Select

func (w *Wredis) Select(db uint) error

Select selects the Database specified by the parameter. We use an unsigned int because Redis databases are numbered using a zero based index. See http://redis.io/commands

func (*Wredis) SelectAndFlushDb

func (w *Wredis) SelectAndFlushDb(db uint) error

SelectAndFlushDb is a convenience method for flushing a specified DB

func (*Wredis) Set

func (w *Wredis) Set(key, value string) error

Set sets a key's string value. See http://redis.io/commands/set

func (*Wredis) SetEx

func (w *Wredis) SetEx(key, value string, seconds int) error

SetEx sets key's to value with an expiry time measured in seconds. See http://redis.io/commands/setex

func (*Wredis) SetExDuration

func (w *Wredis) SetExDuration(key, value string, dur time.Duration) error

SetExDuration is a convenience method to set a key's value with and expiry time.

Jump to

Keyboard shortcuts

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