Browse Source

Improve documentation.

Gary Burd 13 năm trước cách đây
mục cha
commit
a0e4c11621
4 tập tin đã thay đổi với 39 bổ sung11 xóa
  1. 22 4
      README.markdown
  2. 3 3
      redis/reply_test.go
  3. 4 4
      redis/script.go
  4. 10 0
      redis/script_test.go

+ 22 - 4
README.markdown

@@ -1,14 +1,32 @@
 Redigo
 ======
 
-Redigo is a [Go](http://golang.org/) client for the [Redis](http://redis.io/)
-database.
+Redigo is a [Go](http://golang.org/) client for the [Redis](http://redis.io/) database.
 
-The Redigo API reference is available on
-[GoPkgDoc](http://gopkgdoc.appspot.com/pkg/github.com/garyburd/redigo/redis).
+Features
+-------
+
+* An [fmt.Print-like](http://go.pkgdoc.org/github.com/garyburd/redigo/redis#Executing_Commands) API with support for all Redis commands.
+* [Pipelining](http://go.pkgdoc.org/github.com/garyburd/redigo/redis#Pipelining), including pipelined transactions.
+* [Publish/Subscribe](http://go.pkgdoc.org/github.com/garyburd/redigo/redis#Publish_and_Subscribe).
+* [Connection pooling](http://go.pkgdoc.org/github.com/garyburd/redigo/redis#Pool).
+* [Script helper object](http://go.pkgdoc.org/github.com/garyburd/redigo/redis#Script) with optimistic use of EVALSHA.
+
+Documentation
+-------------
+
+The Redigo API reference is available on [GoPkgDoc](http://gopkgdoc.appspot.com/pkg/github.com/garyburd/redigo/redis).
+
+Installation
+------------
 
 Install Redigo using the "go get" command:
 
     go get github.com/garyburd/redigo/redis
 
+The Go distribution is Redigo's only dependency.
+
+License
+-------
+
 Redigo is available under the [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html).

+ 3 - 3
redis/reply_test.go

@@ -26,7 +26,7 @@ import (
 func ExampleBool() {
 	c, err := dial()
 	if err != nil {
-		return
+		panic(err)
 	}
 	defer c.Close()
 
@@ -40,7 +40,7 @@ func ExampleBool() {
 func ExampleInt() {
 	c, err := dial()
 	if err != nil {
-		return
+		panic(err)
 	}
 	defer c.Close()
 
@@ -57,7 +57,7 @@ func ExampleInt() {
 func ExampleString() {
 	c, err := dial()
 	if err != nil {
-		return
+		panic(err)
 	}
 	defer c.Close()
 

+ 4 - 4
redis/script.go

@@ -55,10 +55,10 @@ func (s *Script) args(spec string, keysAndArgs []interface{}) []interface{} {
 	return args
 }
 
-// Do evalutes the script. Under the covers, Do attempts to evaluate the script
-// using the EVALSHA command. If the command fails because the script is not
-// loaded, then Do evaluates the script using the EVAL command (thus causing
-// the script to load).
+// Do evalutes the script. Under the covers, Do optimistically evaluates the
+// script using the EVALSHA command. If the command fails because the script is
+// not loaded, then Do evaluates the script using the EVAL command (thus
+// causing the script to load).
 func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
 	v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...)
 	if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") {

+ 10 - 0
redis/script_test.go

@@ -22,6 +22,16 @@ import (
 	"time"
 )
 
+func ExampleScript(c redis.Conn, reply interface{}, err error) {
+	// Initialize a package-level variable with a script.
+	var getScript = redis.NewScript(1, `return redis.call('get', KEYS[1])`)
+
+	// In a function, use the script Do method to evaluate the script. The Do
+	// method optimistically uses the EVALSHA command. If the script is not
+	// loaded, then the Do method falls back to the EVAL command.
+	reply, err = getScript.Do(c, "foo")
+}
+
 func TestScript(t *testing.T) {
 	c, err := dial()
 	if err != nil {