Categorygithub.com/mdouchement/xredis
modulepackage
0.2.0
Repository: https://github.com/mdouchement/xredis.git
Documentation: pkg.go.dev

# README

xredis

GoDoc

Handy wrapper around github.com/redis/go-redis/v9 package. All the Redis client methods are usable on the xredis client.

Usage

  • Script

    const lua = `local age=redis.call("get", KEYS[1])
    local result="Hello "..ARGV[1].." "..KEYS[1]..", you are "..age.." years old!"
    return result`
    
    func main() {
        ctx := context.Background()
        xclient := xredis.New(redisClient)
    
        script := xredis.NewScript(lua)
    
        err := xclient.Set(ctx, "Abitbol", 42, time.Hour).Err()
        if err != nil {
            panic(err)
        }
    
        value, err := xclient.Run(ctx, script, []string{"Abitbol"}, "George")
        if err != nil {
            panic(err)
        }
    
        fmt.Println(value.String())
        // => Hello George Abitbol, you are 42 years old!
    }
    
  • Value object is a JSON value?

    json.Unmarshal(value.Bytes(), &object)
    

License

MIT

Contributing

All PRs are welcome.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

# Functions

New returns a new Client.
NewScript returns a new Script.
NewValue returns a new Value based on the given Redis result value.

# Variables

ErrNotASlice is used when a value is not castable into a slice.

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

A Client defines all client Redis actions (Client or ClusterClient).