Browse Source

Improve doc comments.

Gary Burd 13 years ago
parent
commit
a2aa5e7bbc
6 changed files with 46 additions and 47 deletions
  1. 0 1
      redis/conn.go
  2. 6 6
      redis/redis.go
  3. 27 27
      redis/reply.go
  4. 0 0
      redis/reply_test.go
  5. 6 6
      redis/script.go
  6. 7 7
      redis/script_test.go

+ 0 - 1
redis/conn.go

@@ -207,7 +207,6 @@ func (c *conn) parseReply() (interface{}, error) {
 	return nil, errors.New("redigo: unpexected response line")
 	return nil, errors.New("redigo: unpexected response line")
 }
 }
 
 
-// Send sends a command for the server without waiting for a reply.
 func (c *conn) Send(cmd string, args ...interface{}) error {
 func (c *conn) Send(cmd string, args ...interface{}) error {
 	if err := c.writeN('*', 1+len(args)); err != nil {
 	if err := c.writeN('*', 1+len(args)); err != nil {
 		return c.fatal(err)
 		return c.fatal(err)

+ 6 - 6
redis/redis.go

@@ -20,9 +20,9 @@
 // Connections
 // Connections
 //
 //
 // The Conn interface is the primary interface for working with Redis.
 // The Conn interface is the primary interface for working with Redis.
-// Applications create connections by calling the Dial or DialWithTimeout
-// functions. In the future, functions will be added for creating pooled
-// connections and sharded connections.
+// Applications create connections by calling the Dial, DialWithTimeout or
+// NewConn functions. In the future, functions will be added for creating
+// pooled connections and sharded connections.
 //
 //
 // The application must call the connection Close method when the application
 // The application must call the connection Close method when the application
 // is done with the connection.
 // is done with the connection.
@@ -35,7 +35,7 @@
 //
 //
 // Arguments of type string and []byte are sent to the server as is. All other
 // Arguments of type string and []byte are sent to the server as is. All other
 // types are formatted using the fmt.Fprint function. Command replies are
 // types are formatted using the fmt.Fprint function. Command replies are
-// represented as Go types as follows:
+// represented using the following Go types:
 //
 //
 //  Redis type          Go type
 //  Redis type          Go type
 //  error               redis.Error
 //  error               redis.Error
@@ -44,8 +44,8 @@
 //  bulk                []byte or nil if value not present.
 //  bulk                []byte or nil if value not present.
 //  multi-bulk          []interface{} or nil if value not present.
 //  multi-bulk          []interface{} or nil if value not present.
 // 
 // 
-// Applications can use type assertions or type switches to determine 
-// the actual type of a reply.
+// Applications can use type assertions or type switches to determine the type
+// of a reply.
 //
 //
 // Pipelining
 // Pipelining
 //
 //

+ 27 - 27
redis/result.go → redis/reply.go

@@ -20,13 +20,13 @@ import (
 )
 )
 
 
 var (
 var (
-	errUnexpectedResultType = errors.New("redigo: unexpected result type")
+	errUnexpectedReplyType = errors.New("redigo: unexpected reply type")
 )
 )
 
 
-// Int is a helper that converts a Redis result to an int. Integer results are
-// returned directly. Bulk responses are interpreted as signed decimal strings.
-// If err is not equal to nil or the result type is not integer or bulk, then
-// Int returns an error.
+// Int is a helper that converts a Redis reply to an int. Integer replies are
+// returned directly. Bulk replies are interpreted as signed decimal strings.
+// If err is not equal to nil or the reply is not an integer or bulk value,
+// then Int returns an error.
 func Int(v interface{}, err error) (int, error) {
 func Int(v interface{}, err error) (int, error) {
 	if err != nil {
 	if err != nil {
 		return 0, err
 		return 0, err
@@ -40,13 +40,13 @@ func Int(v interface{}, err error) (int, error) {
 	case Error:
 	case Error:
 		return 0, v
 		return 0, v
 	}
 	}
-	return 0, errUnexpectedResultType
+	return 0, errUnexpectedReplyType
 }
 }
 
 
-// String is a helper that converts a Redis result to a string. Redis bulk
-// responses are returned as a string. Redis integer responses are formatted as
-// as a signed decimal string. If err is not equal to nil or the result type is
-// not bulk or integer, then String returns an error.
+// String is a helper that converts a Redis reply to a string. Bulk replies are
+// returned as a string. Integer replies are formatted as as a signed decimal
+// string. If err is not equal to nil or the reply is not an integer or bulk
+// value, then Int returns an error.
 func String(v interface{}, err error) (string, error) {
 func String(v interface{}, err error) (string, error) {
 	if err != nil {
 	if err != nil {
 		return "", err
 		return "", err
@@ -59,13 +59,13 @@ func String(v interface{}, err error) (string, error) {
 	case Error:
 	case Error:
 		return "", v
 		return "", v
 	}
 	}
-	return "", errUnexpectedResultType
+	return "", errUnexpectedReplyType
 }
 }
 
 
-// Bytes is a helper that converts a Redis result to slice of bytes. Redis bulk
-// responses are returned as is. Redis integer responses are formatted as as a
-// signed decimal string. If err is not equal to nil or the result type is not
-// bulk or integer, then Bytes returns an error.
+// Bytes is a helper that converts a Redis reply to slice of bytes.  Bulk
+// replies are returned as is. Integer replies are formatted as as a signed
+// decimal string. If err is not equal to nil or the reply is not an integer
+// or bulk value, then Int returns an error.
 func Bytes(v interface{}, err error) ([]byte, error) {
 func Bytes(v interface{}, err error) ([]byte, error) {
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
@@ -78,12 +78,12 @@ func Bytes(v interface{}, err error) ([]byte, error) {
 	case Error:
 	case Error:
 		return nil, v
 		return nil, v
 	}
 	}
-	return nil, errUnexpectedResultType
+	return nil, errUnexpectedReplyType
 }
 }
 
 
-// Bool is a helper that converts a Redis result to a bool. Bool returns true
-// if the result is the integer 1, false if the result is the integer 0.  If
-// err is not equal to nil or the result is not the integer 0 or 1, then Bool
+// Bool is a helper that converts a Redis reply eo a bool. Bool returns true if
+// the reply is the integer 1 and false if the reply is the integer 0.  If err
+// is not equal to nil or the reply is not the integer 0 or 1, then Bool
 // returns an error.
 // returns an error.
 func Bool(v interface{}, err error) (bool, error) {
 func Bool(v interface{}, err error) (bool, error) {
 	if err != nil {
 	if err != nil {
@@ -100,7 +100,7 @@ func Bool(v interface{}, err error) (bool, error) {
 	case Error:
 	case Error:
 		return false, v
 		return false, v
 	}
 	}
-	return false, errUnexpectedResultType
+	return false, errUnexpectedReplyType
 }
 }
 
 
 // Subscribe represents a subscribe or unsubscribe notification.
 // Subscribe represents a subscribe or unsubscribe notification.
@@ -126,40 +126,40 @@ type Message struct {
 	Data []byte
 	Data []byte
 }
 }
 
 
-// Notification returns the result from the Conn Receive method as a
+// Notification is a helper that returns a pub/sub notification as a
 // Subscription or a Message.
 // Subscription or a Message.
 func Notification(v interface{}, err error) (interface{}, error) {
 func Notification(v interface{}, err error) (interface{}, error) {
 	if err != nil {
 	if err != nil {
 		return nil, err
 		return nil, err
 	}
 	}
-	err = errUnexpectedResultType
+	err = errUnexpectedReplyType
 	s, ok := v.([]interface{})
 	s, ok := v.([]interface{})
 	if !ok || len(s) != 3 {
 	if !ok || len(s) != 3 {
-		return nil, errUnexpectedResultType
+		return nil, errUnexpectedReplyType
 	}
 	}
 	b, ok := s[0].([]byte)
 	b, ok := s[0].([]byte)
 	if !ok {
 	if !ok {
-		return nil, errUnexpectedResultType
+		return nil, errUnexpectedReplyType
 	}
 	}
 	kind := string(b)
 	kind := string(b)
 
 
 	b, ok = s[1].([]byte)
 	b, ok = s[1].([]byte)
 	if !ok {
 	if !ok {
-		return nil, errUnexpectedResultType
+		return nil, errUnexpectedReplyType
 	}
 	}
 	channel := string(b)
 	channel := string(b)
 
 
 	if kind == "message" {
 	if kind == "message" {
 		data, ok := s[2].([]byte)
 		data, ok := s[2].([]byte)
 		if !ok {
 		if !ok {
-			return nil, errUnexpectedResultType
+			return nil, errUnexpectedReplyType
 		}
 		}
 		return Message{channel, data}, nil
 		return Message{channel, data}, nil
 	}
 	}
 
 
 	count, ok := s[2].(int64)
 	count, ok := s[2].(int64)
 	if !ok {
 	if !ok {
-		return nil, errUnexpectedResultType
+		return nil, errUnexpectedReplyType
 	}
 	}
 
 
 	return Subscription{kind, channel, int(count)}, nil
 	return Subscription{kind, channel, int(count)}, nil

+ 0 - 0
redis/result_test.go → redis/reply_test.go


+ 6 - 6
redis/script.go

@@ -45,10 +45,10 @@ func (s *Script) args(spec string, keysAndArgs []interface{}) []interface{} {
 	return args
 	return args
 }
 }
 
 
-// Do evaluates the script and returns the result. 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 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).
 func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
 func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
 	v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...)
 	v, err := c.Do("EVALSHA", s.args(s.hash, keysAndArgs)...)
 	if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") {
 	if e, ok := err.(Error); ok && strings.HasPrefix(string(e), "NOSCRIPT ") {
@@ -57,14 +57,14 @@ func (s *Script) Do(c Conn, keysAndArgs ...interface{}) (interface{}, error) {
 	return v, err
 	return v, err
 }
 }
 
 
-// SendHash evaluates the script without waiting for the result. The script is
+// SendHash evaluates the script without waiting for the reply. The script is
 // evaluated with the EVALSHA command. The application must ensure that the
 // evaluated with the EVALSHA command. The application must ensure that the
 // script is loaded by a previous call to Send, Do or Load methods.
 // script is loaded by a previous call to Send, Do or Load methods.
 func (s *Script) SendHash(c Conn, keysAndArgs ...interface{}) error {
 func (s *Script) SendHash(c Conn, keysAndArgs ...interface{}) error {
 	return c.Send("EVALSHA", s.args(s.hash, keysAndArgs)...)
 	return c.Send("EVALSHA", s.args(s.hash, keysAndArgs)...)
 }
 }
 
 
-// Send evaluates the script without waiting for the result. 
+// Send evaluates the script without waiting for the reply. 
 func (s *Script) Send(c Conn, keysAndArgs ...interface{}) error {
 func (s *Script) Send(c Conn, keysAndArgs ...interface{}) error {
 	return c.Send("EVAL", s.args(s.src, keysAndArgs)...)
 	return c.Send("EVAL", s.args(s.src, keysAndArgs)...)
 }
 }

+ 7 - 7
redis/script_test.go

@@ -32,15 +32,15 @@ func TestScript(t *testing.T) {
 	// To test fallback in Do, we make script unique by adding comment with current time.
 	// To test fallback in Do, we make script unique by adding comment with current time.
 	script := fmt.Sprintf("--%d\nreturn {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", time.Now().UnixNano())
 	script := fmt.Sprintf("--%d\nreturn {KEYS[1],KEYS[2],ARGV[1],ARGV[2]}", time.Now().UnixNano())
 	s := redis.NewScript(2, script)
 	s := redis.NewScript(2, script)
-	result := []interface{}{[]byte("key1"), []byte("key2"), []byte("arg1"), []byte("arg2")}
+	reply := []interface{}{[]byte("key1"), []byte("key2"), []byte("arg1"), []byte("arg2")}
 
 
 	v, err := s.Do(c, "key1", "key2", "arg1", "arg2")
 	v, err := s.Do(c, "key1", "key2", "arg1", "arg2")
 	if err != nil {
 	if err != nil {
 		t.Errorf("s.Do(c, ...) returned %v", err)
 		t.Errorf("s.Do(c, ...) returned %v", err)
 	}
 	}
 
 
-	if !reflect.DeepEqual(v, result) {
-		t.Errorf("s.Do(c, ..); = %v, want %v", v, result)
+	if !reflect.DeepEqual(v, reply) {
+		t.Errorf("s.Do(c, ..); = %v, want %v", v, reply)
 	}
 	}
 
 
 	err = s.Load(c)
 	err = s.Load(c)
@@ -54,8 +54,8 @@ func TestScript(t *testing.T) {
 	}
 	}
 
 
 	v, err = c.Receive()
 	v, err = c.Receive()
-	if !reflect.DeepEqual(v, result) {
-		t.Errorf("s.SendHash(c, ..); s.Recevie() = %v, want %v", v, result)
+	if !reflect.DeepEqual(v, reply) {
+		t.Errorf("s.SendHash(c, ..); s.Recevie() = %v, want %v", v, reply)
 	}
 	}
 
 
 	err = s.Send(c, "key1", "key2", "arg1", "arg2")
 	err = s.Send(c, "key1", "key2", "arg1", "arg2")
@@ -64,8 +64,8 @@ func TestScript(t *testing.T) {
 	}
 	}
 
 
 	v, err = c.Receive()
 	v, err = c.Receive()
-	if !reflect.DeepEqual(v, result) {
-		t.Errorf("s.Send(c, ..); s.Recevie() = %v, want %v", v, result)
+	if !reflect.DeepEqual(v, reply) {
+		t.Errorf("s.Send(c, ..); s.Recevie() = %v, want %v", v, reply)
 	}
 	}
 
 
 }
 }