Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
黄成意
/
go_sku_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
cc25de7b
authored
Nov 18, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
b7c80abf
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
123 additions
and
3 deletions
doc/test/r2.go
doc/test/r3.go
pkg/gredis/redis.go
service/service_ly.go
service/service_zy.go
doc/test/r2.go
0 → 100644
View file @
cc25de7b
package
main
import
(
"fmt"
"github.com/gomodule/redigo/redis"
"log"
)
func
main
()
{
c1
,
err
:=
redis
.
Dial
(
"tcp"
,
"192.168.1.235:6379"
)
if
err
!=
nil
{
log
.
Fatalln
(
err
)
}
if
_
,
err
:=
c1
.
Do
(
"AUTH"
,
"icDb29mLy2s"
);
err
!=
nil
{
c1
.
Close
()
log
.
Fatalln
(
err
)
}
defer
c1
.
Close
()
good_id
:=
[]
interface
{}{
"spu"
,
"2160558271613306802"
,
"2160551632152235701"
}
// res1,err := c1.Do("hmget","spu","2160558271613306802","2160551632152235701")
res1
,
err
:=
c1
.
Do
(
"hmget"
,
"spu"
,
good_id
)
reply
,
err
:=
redis
.
Strings
(
res1
,
err
)
//if err != nil {
// fmt.Print(err,"错误")
// // handle error
//}
fmt
.
Println
(
reply
)
//if _, err := redis.Scan(reply, &value1,&value2); err != nil {
// // handle error
// }
// fmt.Print(value1,value2)
return
}
doc/test/r3.go
0 → 100644
View file @
cc25de7b
package
main
import
(
"fmt"
"github.com/gomodule/redigo/redis"
_
"reflect"
)
type
Student
struct
{
Id
int
Name
string
}
func
(
s
Student
)
EchoName
(
name
string
){
fmt
.
Println
(
"我的名字是:"
,
name
)
}
func
main
()
{
c1
,
err
:=
redis
.
Dial
(
"tcp"
,
"192.168.1.235:6379"
)
if
err
!=
nil
{
}
if
_
,
err
:=
c1
.
Do
(
"AUTH"
,
"icDb29mLy2s"
);
err
!=
nil
{
c1
.
Close
()
}
defer
c1
.
Close
()
s
:=
[]
interface
{}{
"spu"
,
"2160558271613306802"
,
"2160551632152235701"
}
//res1,err := c1.Do("hmget","spu","2160558271613306802","2160551632152235701")
res1
,
err
:=
c1
.
Do
(
"hmget"
,
s
...
)
//res1,err := c1.Do("hmget","spu",good_id)
reply
,
err
:=
redis
.
Strings
(
res1
,
err
)
//if err != nil {
// fmt.Print(err,"错误")
// // handle error
//}
fmt
.
Println
(
reply
)
//s := Student{Id: 1, Name: "咖啡色的羊驼"}
//v := reflect.ValueOf(s)
//// 获取方法控制权
//// 官方解释:返回v的名为name的方法的已绑定(到v的持有值的)状态的函数形式的Value封装
//mv := v.MethodByName("EchoName")
//// 拼凑参数
//args := []reflect.Value{reflect.ValueOf("咖啡色的羊驼")}
//
//// 调用函数
//mv.Call(args)
}
\ No newline at end of file
pkg/gredis/redis.go
View file @
cc25de7b
...
...
@@ -64,6 +64,35 @@ func getConn(writeHost, password string, maxIdle, maxActive int) (pool *redis.Po
return
}
/*
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
@param targetIds string 查询的id 切片
eg:
redisConn := gredis.Conn("search_r")
skuArr := gredis.HgetPi(&redisConn,"Self_SelfGoods",[]string{"1001","10005"})
*/
func
Hmget
(
redisCon
string
,
hkey
string
,
targetIds
[]
string
)
map
[
string
]
string
{
redisConn
:=
Conn
(
redisCon
)
defer
redisConn
.
Close
()
skuArr
:=
make
(
map
[
string
]
string
,
0
)
param
:=
[]
interface
{}{
hkey
}
for
_
,
goods_id
:=
range
targetIds
{
param
=
append
(
param
,
goods_id
)
}
res1
,
err
:=
redisConn
.
Do
(
"hmget"
,
param
...
)
reply
,
err
:=
redis
.
Strings
(
res1
,
err
)
//fmt.Println(reply)
for
k
,
goodsInfo
:=
range
reply
{
skuArr
[
targetIds
[
k
]]
=
goodsInfo
}
//fmt.Println(skuArr,err)
return
skuArr
}
/*
批量或者单个查询redis数据,统一返回map[string]string
@param hkey string 集合键值,如sku
...
...
service/service_ly.go
View file @
cc25de7b
...
...
@@ -48,7 +48,7 @@ func (ls *LyService) LyGoodsDetail(ctx *gin.Context, goodsIds []string, goodsRes
}
//批量获取商品详情
skuArr
:=
gredis
.
H
getPi
(
"default_r"
,
"sku"
,
goodsIds
)
skuArr
:=
gredis
.
H
mget
(
"default_r"
,
"sku"
,
goodsIds
)
//为了性能着想,这边也先去批量获取spu的信息
spuList
:=
ls
.
getSpuList
(
skuArr
)
for
goodsId
,
skuStr
:=
range
skuArr
{
...
...
@@ -199,6 +199,6 @@ func (ls *LyService) getSpuList(skuArr map[string]string) (spuList map[string]st
redisConn
:=
gredis
.
Conn
(
"default_r"
)
defer
redisConn
.
Close
()
//批量获取spu详情
spuList
=
gredis
.
H
getPi
(
"default_r"
,
"spu"
,
spuIds
)
spuList
=
gredis
.
H
mget
(
"default_r"
,
"spu"
,
spuIds
)
return
}
service/service_zy.go
View file @
cc25de7b
...
...
@@ -38,7 +38,7 @@ func (qs *ZiyingService) ZyGoodsDetail(ctx *gin.Context,goodsIds []string,goodsR
redisConn
.
Close
();
}()
skuArr
:=
gredis
.
H
getPi2
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
skuArr
:=
gredis
.
H
mget
(
"search_r"
,
"Self_SelfGoods"
,
goodsIds
)
//批量获取商品详情
fast
:=
ctx
.
Request
.
FormValue
(
"power[fast]"
)
for
goods_id
,
info
:=
range
skuArr
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment