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.
Install Bluto with go tool:
go get -u github.com/alibaba-go/bluto/...
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,
})
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.
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
See CONTRIBUTING.md.
Bug reports and feature requests are welcome. If you have any question, please email us at rd@alibaba.ir.
Released under MIT License