浏览代码

Add Support for *string destination in Scan

Fixes #156
Gary Burd 10 年之前
父节点
当前提交
c973522a28
共有 2 个文件被更改,包括 8 次插入0 次删除
  1. 7 0
      redis/scan.go
  2. 1 0
      redis/scan_test.go

+ 7 - 0
redis/scan.go

@@ -183,6 +183,13 @@ func convertAssign(d interface{}, s interface{}) (err error) {
 				err = convertAssignInt(d.Elem(), s)
 			}
 		}
+	case string:
+		switch d := d.(type) {
+		case *string:
+			*d = string(s)
+		default:
+			err = cannotConvert(reflect.ValueOf(d), s)
+		}
 	case []interface{}:
 		switch d := d.(type) {
 		case *[]interface{}:

+ 1 - 0
redis/scan_test.go

@@ -47,6 +47,7 @@ var scanConversionTests = []struct {
 	{[]byte("1"), true},
 	{int64(1), true},
 	{[]byte("t"), true},
+	{"hello", "hello"},
 	{[]byte("hello"), "hello"},
 	{[]byte("world"), []byte("world")},
 	{[]interface{}{[]byte("foo")}, []interface{}{[]byte("foo")}},