package module
Version: v0.0.0-...-44b42e6 Latest Latest

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

Go to latest
Published: Jul 16, 2021 License: MIT Imports: 6 Imported by: 0



Packet GoScriptor implements a way to use redis script more easily


go get -u -v github.com/yshengliao/goscriptor


Let's start with a trivial example:

package main

import (

var (
    scriptDefinition = "scriptKey|0.0.0"

    hello               = "hello"
    _HelloworldTemplate = `
    return 'Hello, World!'

type MyScriptor struct {
    Scriptor *goscriptor.Scriptor

// hello function
func (s *MyScriptor) hello() (string, error) {
    res, err := s.Scriptor.ExecSha(hello, []string{})
    if err != nil {
        return "", err

    return res.(string), nil

func main() {
    opt := &goscriptor.Option{
        Host:     "",
        Port:     6379,
        Password: "",
        DB:       0,
        PoolSize: 10,

    scripts := map[string]string{
        hello: _HelloworldTemplate,

    scriptor, err := goscriptor.NewDB(opt, 1, scriptDefinition, &scripts)
    if err != nil {

    myscript := &MyScriptor{
        Scriptor: scriptor,
    res, err := myscript.hello()
    if err != nil {

  • testify

      go get -u -v github.com/stretchr/testify
  • go-redis

      go get -u -v github.com/go-redis/redis/v8
  • miniredis

      go get -u -v github.com/alicebob/miniredis/v2
  • null.v3

      go get -u -v gopkg.in/guregu/null.v3


  1. Add test cases using "testify".
  2. Add redis script test method.
  3. script_test unit test.
  4. Improve or remove useless code.
  5. Check code formatting.



Package doc is a generated GoDoc package. Packet goscriptor implements a way to use redis script more easily



This section is empty.


View Source
var EmptyRedisReplyValue = &RedisReplyValue{value: nil}

EmptyRedisReplyValue -


func GetNullableInt

func GetNullableInt(value *RedisReplyValue) (null.Int, error)

GetNullableInt -

func GetNullableString

func GetNullableString(value *RedisReplyValue) null.String

GetNullableString -


type Option

type Option struct {
	Host     string
	Port     int
	Password string
	DB       int
	PoolSize int

Option - Redis Option

func (*Option) Create

func (opt *Option) Create() *redis.Client

Create - create a new redis descriptor

type RedisArrayReplyReader

type RedisArrayReplyReader struct {
	// contains filtered or unexported fields

RedisArrayReplyReader -

func NewRedisArrayReplyReader

func NewRedisArrayReplyReader(redisReply []interface{}) *RedisArrayReplyReader

NewRedisArrayReplyReader -

func (*RedisArrayReplyReader) ForEach

func (r *RedisArrayReplyReader) ForEach(action func(i int, v *RedisReplyValue) error) error

ForEach -

func (*RedisArrayReplyReader) GetLength

func (r *RedisArrayReplyReader) GetLength() int

GetLength -

func (*RedisArrayReplyReader) HasNext

func (r *RedisArrayReplyReader) HasNext() bool

HasNext -

func (*RedisArrayReplyReader) ReadArray

ReadArray -

func (*RedisArrayReplyReader) ReadFloat64

func (r *RedisArrayReplyReader) ReadFloat64(defaultValue float64) (float64, error)

ReadFloat64 -

func (*RedisArrayReplyReader) ReadInt32

func (r *RedisArrayReplyReader) ReadInt32(defaultValue int32) (int32, error)

ReadInt32 -

func (*RedisArrayReplyReader) ReadInt64

func (r *RedisArrayReplyReader) ReadInt64(defaultValue int64) (int64, error)

ReadInt64 -

func (*RedisArrayReplyReader) ReadString

func (r *RedisArrayReplyReader) ReadString() string

ReadString -

func (*RedisArrayReplyReader) ReadValue

func (r *RedisArrayReplyReader) ReadValue() *RedisReplyValue

ReadValue -

func (*RedisArrayReplyReader) SkipValue

func (r *RedisArrayReplyReader) SkipValue()

SkipValue -

type RedisReplyValue

type RedisReplyValue struct {
	// contains filtered or unexported fields

RedisReplyValue -

func NewRedisReplyValue

func NewRedisReplyValue(value interface{}) *RedisReplyValue

NewRedisReplyValue -

func (*RedisReplyValue) AsFloat64

func (v *RedisReplyValue) AsFloat64(defaultValue float64) (float64, error)

AsFloat64 -

func (*RedisReplyValue) AsInt32

func (v *RedisReplyValue) AsInt32(defaultValue int32) (int32, error)

AsInt32 -

func (*RedisReplyValue) AsInt64

func (v *RedisReplyValue) AsInt64(defaultValue int64) (int64, error)

AsInt64 -

func (*RedisReplyValue) AsString

func (v *RedisReplyValue) AsString() string

AsString -

func (*RedisReplyValue) IsNil

func (v *RedisReplyValue) IsNil() bool

IsNil -

func (*RedisReplyValue) ToArrayReplyReader

func (v *RedisReplyValue) ToArrayReplyReader() *RedisArrayReplyReader

ToArrayReplyReader -

func (*RedisReplyValue) Value

func (v *RedisReplyValue) Value() interface{}

Value -

type ScriptDescriptor

type ScriptDescriptor struct {
	Scripts map[string]string
	// contains filtered or unexported fields

Script is a script descriptor

func NewScriptDescriptor

func NewScriptDescriptor(ctx context.Context, client *redis.Client, scripts *map[string]string, redisScriptDefinition string, db int) (*ScriptDescriptor, error)

NewScriptDescriptor creates a new script descriptor

func (*ScriptDescriptor) LoadScripts

func (scriptDescriptor *ScriptDescriptor) LoadScripts(ctx context.Context, client *redis.Client, redisScriptDefinition string, db int) error

LoadScripts loads the scripts

func (*ScriptDescriptor) Register

func (scriptDescriptor *ScriptDescriptor) Register(ctx context.Context, client *redis.Client, scripts *map[string]string, redisScriptDefinition string, db int) error

Registers a script

type Scriptor

type Scriptor struct {
	Client *redis.Client

	CTX context.Context
	// contains filtered or unexported fields

Scriptor - the script manager

func New

func New(client *redis.Client, scriptDB int, redisScriptDefinition string, scripts *map[string]string) (*Scriptor, error)

New - create a new scriptor with the redis client

func NewDB

func NewDB(opt *Option, scriptDB int, redisScriptDefinition string, scripts *map[string]string) (*Scriptor, error)

NewDB - create a new Scriptor with a new redis client

func (*Scriptor) Exec

func (s *Scriptor) Exec(script string, keys []string, args ...interface{}) (interface{}, error)

Exec - execute the script

func (*Scriptor) ExecSha

func (s *Scriptor) ExecSha(scriptname string, keys []string, args ...interface{}) (interface{}, error)

ExecSha - execute the script

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL