Commit 3be929a2 by huangchengyi

Merge branch 'dev' of http://119.23.72.7/mushishixian/search_server into dev

# Conflicts:
#	pkg/gredis/redis.go
#	test/test4.go
parents a8d4746d 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"
)
......
package gredis
import (
"encoding/json"
"github.com/gomodule/redigo/redis"
"search_server/pkg/config"
"time"
......@@ -9,20 +8,18 @@ import (
type IchuntRedis struct {
type ichuntRedis 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 := &IchuntRedis{}
ichuntRedis := &ichuntRedis{}
ichuntRedis.RedisList = make(map[string]*redis.Pool,0)
RedisDatabaseMap := config.BuildRedisConfgs()
for redisKey,redisConfig := range RedisDatabaseMap{
......@@ -63,108 +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 false,err
}
return redis.Bool(conn.Do("SETNX", key, value))
}
//设置过期时间
func EXP(key string, ttl int) (bool,error) {
conn := writeConn.Get()
defer conn.Close()
return redis.Bool(conn.Do("EXP", key, ttl))
}
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))
}
......@@ -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
}
......@@ -10,14 +10,14 @@ func main() {
a=1.69*100
b=1.7*10
c=a*b/(100*10)
//正确结果2.873
//ȷ2.873
fmt.Println(c)
//fmt.Println(fmt.Sprintf("%.2f",c))
//fmt.Println(FloatRound(c,2))
}
// 截取小数位数
// ȡСλ
func FloatRound(f float64, n int) float64 {
format := "%." + strconv.Itoa(n) + "f"
//fmt.Println(format)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment