-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
240 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"testing" | ||
) | ||
|
||
var NotExistsKey = "NotExistsKey" | ||
|
||
func TestExistsValue(t *testing.T) { | ||
r := NewRedis() | ||
ctx := context.Background() | ||
result, err := r.Exists(ctx, "666").Result() | ||
if err != nil { | ||
log.Fatalln(err) | ||
return | ||
} | ||
fmt.Println(result) | ||
|
||
} | ||
|
||
func TestHMGet(t *testing.T) { | ||
r := NewRedis() | ||
ctx := context.Background() | ||
r.HMSet(ctx, "666", "name", "john", "age", 30) | ||
result, err := r.HMGet(ctx, "666", "name", "age").Result() | ||
if err != nil { | ||
log.Fatalln(err) | ||
return | ||
} | ||
fmt.Println(result) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,36 @@ | ||
# lpush | ||
# 1. lpush | ||
|
||
这个功能用的时候要注意不能直接放结构体变量进去, | ||
一般来说还是自己做解析,(记得可以自己为其实现 解析和读取的方法,然后就可以放了) | ||
一般来说还是自己做解析,(记得可以自己为其实现 解析和读取的方法,然后就可以放了) | ||
|
||
# 2. Exists方法 | ||
|
||
用于判断该键是否存在 | ||
|
||
``` | ||
func TestExistsValue(t *testing.T) { | ||
r := NewRedis() | ||
ctx := context.Background() | ||
result, err := r.Exists(ctx, "666").Result() | ||
if err != nil { | ||
log.Fatalln(err) | ||
return | ||
} | ||
fmt.Println(result) | ||
} | ||
``` | ||
|
||
存在会返回1,不存在返回0 | ||
|
||
# 3. HMGET | ||
|
||
```go | ||
result, err := r.HMGet(ctx, "666", "name", "age").Result() | ||
``` | ||
666是键,是map的名字,后边的是这个map里边的键的名字 | ||
hmget中的m应该指的是many | ||
|
||
对于hget,便是只取一个filed的值 | ||
|
||
hset,也是只设置一个 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func TestGetNilSlice(t *testing.T) { | ||
oidPgid := make(map[string][]string) | ||
c := oidPgid["123"] | ||
fmt.Println(c == nil) | ||
c = make([]string, 0) | ||
oidPgid["123"] = c | ||
c = oidPgid["123"] | ||
fmt.Println(c == nil) | ||
} | ||
|
||
func TestNilSliceAppend(t *testing.T) { | ||
oidPgid := make(map[string][]string) | ||
c := oidPgid["123"] | ||
c = append(c, "123") | ||
fmt.Println(oidPgid["123"]) | ||
oidPgid["123"] = c | ||
fmt.Println(oidPgid["123"]) | ||
} | ||
|
||
func TestRangeKey(t *testing.T) { | ||
appendGids := make(map[string]bool) | ||
if appendGids["66"] == false { | ||
fmt.Println("000") | ||
} else { | ||
fmt.Println("111") | ||
} | ||
for k, v := range appendGids { | ||
fmt.Println(k, ":", v) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package main | ||
|
||
import "testing" | ||
|
||
var s = ` | ||
"res": { | ||
"location": [ | ||
{ | ||
"category": 0, | ||
"car_id": "6eda84f3f1de4feaae9814e1b714977b", | ||
"cell_id": 65484, | ||
"type": 1, | ||
"degree": 322, | ||
"timestamp": 1574672308, | ||
"altitude": 1, | ||
"mcc": 460, | ||
"t_type": "ZJ210", | ||
"longitude": 408545640, | ||
"locate_error": 6, | ||
"tid": "f4a87b51313b4f758f9b4da38f6b59f9", | ||
"snr": 40, | ||
"address": "", | ||
"latitude": 80277480, | ||
"clongitude": 408588067, | ||
"clatitude": 80288988, | ||
"mnc": 0, | ||
"speed": 42, | ||
"locate_type": 1 | ||
} | ||
] | ||
}, | ||
"packet_type": "S13" | ||
} | ||
` | ||
|
||
func TestOp(t *testing.T) { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"github.com/tidwall/gjson" | ||
"io" | ||
"net/http" | ||
) | ||
|
||
var BaseUrl = `http://peifeng.site:8000/` | ||
|
||
func ParseResponseByMqp(response *http.Response) (map[string]any, error) { | ||
var res map[string]any | ||
body, err := io.ReadAll(response.Body) | ||
if err == nil { | ||
err = json.Unmarshal(body, &res) | ||
} | ||
return res, err | ||
} | ||
|
||
func ParseResponseGJson(response *http.Response) (gjson.Result, error) { | ||
var parse gjson.Result | ||
body, err := io.ReadAll(response.Body) | ||
if err == nil { | ||
parse = gjson.Parse(string(body)) | ||
} | ||
return parse, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package api | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
type Flower struct { | ||
*http.Client | ||
} | ||
|
||
func (o *Flower) FlowerSortShow(data map[string]any) { | ||
url := "http://peifeng.site:8000/flower/sort/?id=0041" | ||
// 将数据编码为 JSON 格式 | ||
jsonData, err := json.Marshal(data) | ||
if err != nil { | ||
fmt.Println("Error encoding JSON:", err) | ||
return | ||
} | ||
req, err := http.NewRequest("GET", url, bytes.NewBuffer(jsonData)) | ||
if err != nil { | ||
fmt.Println("Error creating request:", err) | ||
return | ||
} | ||
req.Header.Set("Content-Type", "application/json") | ||
resp, err := o.Do(req) | ||
if err != nil { | ||
fmt.Println("Error sending request:", err) | ||
return | ||
} | ||
|
||
defer resp.Body.Close() | ||
// 打印响应内容 | ||
fmt.Println("Response:", resp.Status) | ||
fmt.Println("开始那啥") | ||
response, err := ParseResponseGJson(resp) | ||
fmt.Println("那啥结束") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Println("err", err) | ||
fmt.Println(response.Get("data")) | ||
fmt.Println("err", err) | ||
|
||
fmt.Printf(":::") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package api | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
) | ||
|
||
func TestFlower_FlowerSortShow(t *testing.T) { | ||
client := &http.Client{} | ||
f := Flower{client} | ||
f.FlowerSortShow(nil) | ||
} |