Skip to content

Bluto is easy to use go redis client based on Redigo.

License

Notifications You must be signed in to change notification settings

alibaba-go/bluto

Repository files navigation

Go GoDoc Go Report Card CII Best Practices Coverage

Bluto

Bluto is a golang implementation of Redis client based on Redigo. The client manages a connection pool for each node and uses goroutine to execute as concurrently as possible, leading to its high efficiency and low latency.

Supported:

  • Most commands of keys, strings, lists, sets, sorted sets, and hashes.

Documentation

API Reference

Installation

Install Bluto with go tool:

    go get -u github.com/alibaba-go/bluto/...

Usage

To use Redis cluster, you need to import the package and create a new Bluto client with a config:

import "https://github.com/alibaba-go/bluto"

bluto, err := bluto.New(
    &bluto.config{
    Address:              "localhost:6379",
    Password              "password"
    ConnectTimeoutSeconds: 10,
    ReadTimeoutSeconds:    10,
    })

Basic

Bluto gives you a commander by calling Borrow(), an interface to run Redis commands (GET, SELECT, etc.) over a Redis connection pool that simplifies all the pool's management.

RESTRICTION:

  • The first argument of the command should be a result.
  • All commands should end with Commit().
  • Optional arguments are passed as variadic args.

See full redis commands:

bluto.Borrow().Set(&setResult, "key", "value", SetOptionKEEPTTL{}).Commit()
bluto.Borrow().Get(&getResult, "key").Commit()
bluto.Borrow().Incr(&incrResult, "key").Commit()

You can also chain redis commands like this:

bluto.Borrow().Select(&selectResult, 2).Set(&setResult, "key", "value",SetOptionKEEPTTL{}).Incr(&incrResult, "key").Commit()
bluto.Borrow().Select(&selectResult, 2).Get(&getResult, "key").Decr(&decrResult, "key").Del(&delResult, "key").Commit()

Also, you can use Values and Scan to convert replies to multiple values with different types.

Command's Options

You can pass options as variadic args as last arguments. The Option for each command is an interface that is satisfied by defined option structs. You can pass multiple options like this:

bluto.Borrow().Set(&setResult, "key", "value", SetOptionEX{EX:1}, SetOptionNX{}, SetOptionKEEPTTL{}).Commit()

For more advanced examples look at example

Contributing

See CONTRIBUTING.md.

Contact

Bug reports and feature requests are welcome. If you have any question, please email us at rd@alibaba.ir.

License

Released under MIT License

About

Bluto is easy to use go redis client based on Redigo.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages