redigotest

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

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

Go to latest
Published: Oct 21, 2016 License: MIT Imports: 3 Imported by: 0

README

redigotest

Build Status Go Report Card

redigotest contains test examples for using redigo.

Get type of reply after exectuing commands

It'll use GetReplyType() with test Redis commands to see what's the reply type in Golang for each Redis command.

GetReplyType(): do cmds
FLUSHALL ok, args: [], ret type: string, ret: OK
INFO ok, args: [keyspace], ret type: []uint8, ret: [35 32 75 101 121 115 112 97 99 101 13 10]
SET ok, args: [student:num 0], ret type: string, ret: OK
GET ok, args: [student:num], ret type: []uint8, ret: [48]
HSET ok, args: [student:1 name Bob], ret type: int64, ret: 1
HGET ok, args: [student:1 name], ret type: []uint8, ret: [66 111 98]
INCR ok, args: [student:num], ret type: int64, ret: 1
GET ok, args: [student:num], ret type: []uint8, ret: [49]
LPUSH ok, args: [laststudents 1 2 3], ret type: int64, ret: 3
LRANGE ok, args: [laststudents 0 -1], ret type: []interface {}, ret: [[51] [50] [49]]
HSCAN ok, args: [student:1 0], ret type: []interface {}, ret: [[48] [[110 97 109 101] [66 111 98] [97 103 101] [50 48]]]
Redis command reply types -> Go types
Redis command reply types are represented using the following Go types:

Redis type              Go type
error                   redis.Error
integer                 int64
simple string           string
bulk string             []byte or nil if value not present.
array                   []interface{} or nil if value not present.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetReplyType

func GetReplyType(c redis.Conn, cmds []Command)

GetReplyType does test Redis commands to see what's the reply type in Golang for each Redis command.

Example

ExampleGetReplyType tests the return value and types of Redis Commands.

package main

import (
	"github.com/northbright/redigotest"
)

func main() {
	cmds := []redigotest.Command{
		redigotest.Command{Cmd: "FLUSHALL", Args: []interface{}{}},
		redigotest.Command{Cmd: "INFO", Args: []interface{}{"keyspace"}},
		redigotest.Command{Cmd: "SET", Args: []interface{}{"student:num", 0}},
		redigotest.Command{Cmd: "GET", Args: []interface{}{"student:num"}},
		redigotest.Command{Cmd: "HSET", Args: []interface{}{"student:1", "name", "Bob"}},
		redigotest.Command{Cmd: "HSET", Args: []interface{}{"student:1", "age", "20"}},
		redigotest.Command{Cmd: "HGET", Args: []interface{}{"student:1", "name"}},
		redigotest.Command{Cmd: "INCR", Args: []interface{}{"student:num"}},
		redigotest.Command{Cmd: "GET", Args: []interface{}{"student:num"}},
		redigotest.Command{Cmd: "LPUSH", Args: []interface{}{"laststudents", "1", "2", "3"}},
		redigotest.Command{Cmd: "LRANGE", Args: []interface{}{"laststudents", 0, -1}},
		redigotest.Command{Cmd: "HSCAN", Args: []interface{}{"student:1", 0}},
	}

	pool := redigotest.NewRedisPool(":6379", false, "")
	c := pool.Get()
	defer c.Close()

	redigotest.GetReplyType(c, cmds)
}
Output:

func NewRedisPool

func NewRedisPool(server string, requirepass bool, password string) *redis.Pool

NewRedisPool creates a Redis Pool.

func SetInt

func SetInt(c redis.Conn, k string, v interface{})

SetInt tests the return value of "SET" command with integer or string.

Example
package main

import (
	"github.com/northbright/redigotest"
)

func main() {
	var vUint64 uint64 = 12345678
	var vInt64 int64 = 12345678
	var vStr string = "12345678"

	vArr := []interface{}{vUint64, vInt64, vStr}

	pool := redigotest.NewRedisPool(":6379", false, "")
	c := pool.Get()
	defer c.Close()

	for _, v := range vArr {
		redigotest.SetInt(c, "int-test", v)
	}
}
Output:

Types

type Command

type Command struct {
	Cmd  string
	Args []interface{}
}

Command type represents Redis command.

Jump to

Keyboard shortcuts

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