Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_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
1d8d5de0
authored
Jul 06, 2020
by
孙龙
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
up
parent
a9fa6bb9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
18 additions
and
115 deletions
cmd/search_http_server.go
pkg/gredis/redis.go
routes/router.go
test/test4.go
cmd/search_http_server.go
View file @
1d8d5de0
...
...
@@ -5,7 +5,7 @@ import (
"github.com/gin-gonic/gin"
"github.com/micro/go-micro/v2/web"
"search_server/boot"
_
"search_server/controller"
//
_ "search_server/controller"
"search_server/pkg/config"
"search_server/routes"
)
...
...
pkg/gredis/redis.go
View file @
1d8d5de0
package
gredis
import
(
"encoding/json"
"github.com/gomodule/redigo/redis"
"search_server/pkg/config"
"time"
...
...
@@ -9,20 +8,18 @@ import (
type
I
chuntRedis
struct
{
type
i
chuntRedis
struct
{
RedisList
map
[
string
]
*
redis
.
Pool
Current
*
redis
.
Pool
}
func
(
this
*
IchuntRedis
)
Connection
(
connection
string
)
(
*
IchuntRedis
){
this
.
Current
=
this
.
RedisList
[
connection
]
return
this
func
(
this
*
ichuntRedis
)
Conn
(
connection
string
)
(
*
redis
.
Pool
){
return
this
.
RedisList
[
connection
]
}
var
writeConn
,
readConn
*
redis
.
Pool
func
Setup
()
(
err
error
)
{
ichuntRedis
:=
&
I
chuntRedis
{}
ichuntRedis
:=
&
i
chuntRedis
{}
ichuntRedis
.
RedisList
=
make
(
map
[
string
]
*
redis
.
Pool
,
0
)
RedisDatabaseMap
:=
config
.
BuildRedisConfgs
()
for
redisKey
,
redisConfig
:=
range
RedisDatabaseMap
{
...
...
@@ -63,109 +60,4 @@ func getConn(writeHost, password string) (pool *redis.Pool, err error) {
return
}
//最基础的键值操作
func
(
this
*
IchuntRedis
)
Set
(
key
string
,
data
interface
{})
error
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
value
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
return
err
}
_
,
err
=
conn
.
Do
(
"SET"
,
key
,
value
)
if
err
!=
nil
{
return
err
}
return
nil
}
//Redis Setnx(SET if Not eXists) 命令在指定的 key 不存在时,为 key 设置指定的值。
func
(
this
*
IchuntRedis
)
Setnx
(
key
string
,
data
interface
{})
error
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
value
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
return
err
}
_
,
err
=
conn
.
Do
(
"SETNX"
,
key
,
value
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
this
*
IchuntRedis
)
Exists
(
key
string
)
bool
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
exists
,
err
:=
redis
.
Bool
(
conn
.
Do
(
"EXISTS"
,
key
))
if
err
!=
nil
{
return
false
}
return
exists
}
func
(
this
*
IchuntRedis
)
Get
(
key
string
)
(
interface
{},
error
)
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
reply
,
err
:=
conn
.
Do
(
"GET"
,
key
)
if
err
!=
nil
{
return
nil
,
err
}
return
reply
,
nil
}
func
(
this
*
IchuntRedis
)
Delete
(
key
string
)
(
bool
,
error
)
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
return
redis
.
Bool
(
conn
.
Do
(
"DEL"
,
key
))
}
//哈希操作
func
(
this
*
IchuntRedis
)
HSet
(
key
string
,
k
interface
{},
data
interface
{})
error
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
value
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
return
err
}
_
,
err
=
conn
.
Do
(
"HSET"
,
key
,
k
,
value
)
if
err
!=
nil
{
return
err
}
return
nil
}
func
(
this
*
IchuntRedis
)
HGet
(
key
string
,
k
interface
{})
(
interface
{},
error
)
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
reply
,
err
:=
conn
.
Do
(
"HGET"
,
key
,
k
)
if
err
!=
nil
{
return
nil
,
err
}
return
reply
,
nil
}
func
(
this
*
IchuntRedis
)
HDelete
(
key
string
,
k
interface
{})
(
bool
,
error
)
{
conn
:=
this
.
Current
.
Get
()
defer
conn
.
Close
()
return
redis
.
Bool
(
conn
.
Do
(
"HDEL"
,
key
,
k
))
}
routes/router.go
View file @
1d8d5de0
...
...
@@ -14,10 +14,10 @@ func InitRouter() *gin.Engine {
//路由
r
.
POST
(
"/search/bom/autospu"
,
controller
.
AutoSpu
)
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
r
.
POST
(
"search/ZiYing/zyh"
,
controller
.
Zyh
)
//
r.POST("search/ZiYing/zyh", controller.Zyh)
//快手平台相关
r
.
GET
(
"/search/quote"
,
controller
.
QuoteIndex
)
//
r.GET("/search/quote", controller.QuoteIndex)
return
r
}
test/test4.go
0 → 100644
View file @
1d8d5de0
package
main
type
IchuntRedis
struct
{
Abc
map
[
string
]
int
Current
*
int
}
ichuntRedis
:=
&
IchuntRedis
{}
ichuntRedis
.
ichuntRedis
[]
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