目录


package main
import (
"encoding/json"
"fmt"
"github.com/olivere/elastic/v7"
)
func main() {
//初始化一个连接
host := "http://192.168.124.51:9200"
// 这里必须将sniff设置为false,因为使用olivere/elastic连接elasticsearch时,发现连接地址命名输入的时候是地址
// 但是连接时会自动转换成内网地址或者docker中的ip地址,导致服务连接不上
_, err := elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false))
if err != nil {
panic(err)
}
q := elastic.NewMatchQuery("address", "street")
src, err := q.Source()
if err != nil {
panic(err)
}
data, err := json.Marshal(src)
got := string(data)
fmt.Println(got)
}

package main
import (
"context"
"fmt"
"github.com/olivere/elastic/v7"
)
func main() {
//初始化一个连接
host := "http://192.168.124.51:9200"
// 这里必须将sniff设置为false,因为使用olivere/elastic连接elasticsearch时,发现连接地址命名输入的时候是地址
// 但是连接时会自动转换成内网地址或者docker中的ip地址,导致服务连接不上
client, err := elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false))
if err != nil {
panic(err)
}
q := elastic.NewMatchQuery("address", "street")
result, err := client.Search().Index("user").Query(q).Do(context.Background())
if err != nil {
panic(err)
}
total := result.Hits.TotalHits.Value
fmt.Printf("搜索结果数量:%d\n", total)
for _, value := range result.Hits.Hits {
if jsonData, err := value.Source.MarshalJSON(); err == nil {
fmt.Println(string(jsonData))
} else {
panic(err)
}
}
}

package main
import (
"context"
"encoding/json"
"fmt"
"github.com/olivere/elastic/v7"
)
type Account struct {
AccountNum int32 `json:"account_number"`
FirstName string `json:"firstname"`
}
func main() {
//初始化一个连接
host := "http://192.168.124.51:9200"
// 这里必须将sniff设置为false,因为使用olivere/elastic连接elasticsearch时,发现连接地址命名输入的时候是地址
// 但是连接时会自动转换成内网地址或者docker中的ip地址,导致服务连接不上
client, err := elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false))
if err != nil {
panic(err)
}
q := elastic.NewMatchQuery("address", "street")
result, err := client.Search().Index("user").Query(q).Do(context.Background())
if err != nil {
panic(err)
}
total := result.Hits.TotalHits.Value
fmt.Printf("搜索结果数量:%d\n", total)
for _, value := range result.Hits.Hits {
account := Account{}
_ = json.Unmarshal(value.Source, &account)
fmt.Println(account)
}
}

package main
import (
"context"
"encoding/json"
"fmt"
"github.com/olivere/elastic/v7"
"log"
"os"
)
type Account struct {
AccountNum int32 `json:"account_number"`
FirstName string `json:"firstname"`
}
func main() {
//初始化一个连接
host := "http://192.168.124.51:9200"
logger := log.New(os.Stdout, "mxshop", log.LstdFlags)
// 这里必须将sniff设置为false,因为使用olivere/elastic连接elasticsearch时,发现连接地址命名输入的时候是地址
// 但是连接时会自动转换成内网地址或者docker中的ip地址,导致服务连接不上
client, err := elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false),
elastic.SetTraceLog(logger))
if err != nil {
panic(err)
}
q := elastic.NewMatchQuery("address", "street")
result, err := client.Search().Index("user").Query(q).Do(context.Background())
if err != nil {
panic(err)
}
total := result.Hits.TotalHits.Value
fmt.Printf("搜索结果数量:%d\n", total)
for _, value := range result.Hits.Hits {
account := Account{}
_ = json.Unmarshal(value.Source, &account)
fmt.Println(account)
}
account := Account{AccountNum: 15468, FirstName: "immooc bobby"}
put1, err := client.Index().Index("myuser").BodyJson(account).Do(context.Background())
if err != nil {
panic(err)
}
fmt.Printf("Indexed myuser %s to index %s, type %s \n", put1.Id, put1.Index, put1.Type)
}

package main
import (
"context"
"encoding/json"
"fmt"
"github.com/olivere/elastic/v7"
"log"
"os"
)
const goodsMapping = `{
"mappings" : {
"properties" : {
"name" : {
"type" : "text",
"analyzer":"ik_max_word"
},
"id" : {
"type" : "integer"
}
}
}
}`
type Account struct {
AccountNum int32 `json:"account_number"`
FirstName string `json:"firstname"`
}
func main() {
//初始化一个连接
host := "http://192.168.124.51:9200"
logger := log.New(os.Stdout, "mxshop", log.LstdFlags)
// 这里必须将sniff设置为false,因为使用olivere/elastic连接elasticsearch时,发现连接地址命名输入的时候是地址
// 但是连接时会自动转换成内网地址或者docker中的ip地址,导致服务连接不上
client, err := elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false),
elastic.SetTraceLog(logger))
if err != nil {
panic(err)
}
q := elastic.NewMatchQuery("address", "street")
result, err := client.Search().Index("user").Query(q).Do(context.Background())
if err != nil {
panic(err)
}
total := result.Hits.TotalHits.Value
fmt.Printf("搜索结果数量:%d\n", total)
for _, value := range result.Hits.Hits {
account := Account{}
_ = json.Unmarshal(value.Source, &account)
fmt.Println(account)
}
//account := Account{AccountNum: 15468, FirstName: "immooc bobby"}
//put1, err := client.Index().Index("myuser").BodyJson(account).Do(context.Background())
//if err != nil {
// panic(err)
//}
//fmt.Printf("Indexed myuser %s to index %s, type %s \n", put1.Id, put1.Index, put1.Type)
createIndex, err := client.CreateIndex("mygoods").BodyString(goodsMapping).Do(context.Background())
if err != nil {
panic(err)
}
if !createIndex.Acknowledged {
}
}


package model
type EsGoods struct {
ID int32 `json:"id"`
CategoryID int32 `json:"category_id"`
BrandsID int32 `json:"brands_id"`
OnSale bool `json:"on_sale"`
ShipFree bool `json:"ship_free"`
IsNew bool `json:"is_new"`
IsHot bool `json:"is_hot"`
Name string `json:"name"`
ClickNum int32 `json:"click_num"`
SoldNum int32 `json:"sold_num"`
FavNum int32 `json:"fav_num"`
MarketPrice float32 `json:"market_price"`
GoodsBrief string `json:"goods_brief"`
ShopPrice float32 `json:"shop_price"`
}
func (EsGoods) GetIndexName() string {
return "goods"
}
func (EsGoods) GetMapping() string {
goodsMapping := `
{
"mappings" : {
"properties" : {
"brands_id" : {
"type" : "integer"
},
"category_id" : {
"type" : "integer"
},
"click_num" : {
"type" : "integer"
},
"fav_num" : {
"type" : "integer"
},
"id" : {
"type" : "integer"
},
"is_hot" : {
"type" : "boolean"
},
"is_new" : {
"type" : "boolean"
},
"market_price" : {
"type" : "float"
},
"name" : {
"type" : "text",
"analyzer":"ik_max_word"
},
"goods_brief" : {
"type" : "text",
"analyzer":"ik_max_word"
},
"on_sale" : {
"type" : "boolean"
},
"ship_free" : {
"type" : "boolean"
},
"shop_price" : {
"type" : "float"
},
"sold_num" : {
"type" : "long"
}
}
}
}`
return goodsMapping
}
{
"name": "goods_srv",
"host": "192.168.124.9",
"tags": ["imooc", "bobby", "goods", "srv"],
"mysql": {
"host": "192.168.124.51",
"port": 3306,
"user": "root",
"password": "jiushi",
"db": "mxshop_goods_srv"
},
"consul": {
"host": "192.168.124.51",
"port": 8500
},
"es": {
"host": "192.168.124.51",
"port": 9200
}
}
package config
type MysqlConfig struct {
Host string `mapstructure:"host" json:"host"`
Port int `mapstructure:"port" json:"port"`
Name string `mapstructure:"db" json:"db"`
User string `mapstructure:"user" json:"user"`
Password string `mapstructure:"password" json:"password"`
}
type ConsulConfig struct {
Host string `mapstructure:"host" json:"host"`
Port int `mapstructure:"port" json:"port"`
}
type EsConfig struct {
Host string `mapstructure:"host" json:"host"`
Port int `mapstructure:"port" json:"port"`
}
type ServerConfig struct {
Name string `mapstructure:"name" json:"name"`
Host string `mapstructure:"host" json:"host"`
Tags []string `mapstructure:"tags" json:"tags"`
MysqlInfo MysqlConfig `mapstructure:"mysql" json:"mysql"`
ConsulInfo ConsulConfig `mapstructure:"consul" json:"consul"`
EsInfo EsConfig `mapstructure:"es" json:"es"`
}
type NacosConfig struct {
Host string `mapstructure:"host"`
Port uint64 `mapstructure:"port"`
Namespace string `mapstructure:"namespace"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
DataId string `mapstructure:"dataid"`
Group string `mapstructure:"group"`
}
package global
import (
"github.com/olivere/elastic/v7"
"gorm.io/gorm"
"nd/goods_srv/config"
)
var (
DB *gorm.DB
ServerConfig config.ServerConfig
NacosConfig config.NacosConfig
EsClient *elastic.Client
)
package initialize
import (
"context"
"fmt"
"github.com/olivere/elastic/v7"
"log"
"nd/goods_srv/global"
"nd/goods_srv/model"
"os"
)
func InitEs() {
//初始化连接
host := fmt.Sprintf("http://%s:%d", global.ServerConfig.EsInfo.Host, global.ServerConfig.EsInfo.Port)
logger := log.New(os.Stdout, "mxshop", log.LstdFlags)
var err error
global.EsClient, err = elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false),
elastic.SetTraceLog(logger))
if err != nil {
panic(err)
}
//新建mapping和index
exists, err := global.EsClient.IndexExists(model.EsGoods{}.GetIndexName()).Do(context.Background())
if err != nil {
panic(err)
}
if !exists { // 不存在的时候才需要新建mapping
_, err = global.EsClient.CreateIndex(model.EsGoods{}.GetIndexName()).BodyString(model.EsGoods{}.GetMapping()).Do(context.Background())
if err != nil {
panic(err)
}
}
}
func main() {
IP := flag.String("ip", "0.0.0.0", "ip地址")
Port := flag.Int("port", 50058, "端口号") // 这个修改为0,如果我们从命令行带参数启动的话就不会为0
//初始化
initialize.InitLogger()
initialize.InitConfig()
initialize.InitDB()
initialize.InitEs()
zap.S().Info(global.ServerConfig)
//省略。。。


package main
import (
"context"
"fmt"
"github.com/olivere/elastic/v7"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
"log"
"nd/goods_srv/global"
"nd/goods_srv/initialize"
"nd/goods_srv/model"
"os"
"strconv"
"time"
)
func main() {
/* initialize.InitConfig()
dsn := fmt.Sprintf("root:jiushi@tcp(%s:3306)/mxshop_goods_srv?charset=utf8mb4&parseTime=True&loc=Local", global.ServerConfig.MysqlInfo.Host)
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // 慢 SQL 阈值
LogLevel: logger.Info, // Log level
Colorful: true, // 禁用彩色打印
},
)
// 全局模式
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
},
Logger: newLogger,
})
if err != nil {
panic(err)
}
_ = db.AutoMigrate(&model.Category{},
&model.Brands{}, &model.GoodsCategoryBrand{}, &model.Banner{}, &model.Goods{})*/
Mysql2Es()
}
// Mysql2Es 将之前mysql的goods数据保存到es中
func Mysql2Es() {
initialize.InitConfig()
dsn := fmt.Sprintf("root:jiushi@tcp(%s:3306)/mxshop_goods_srv?charset=utf8mb4&parseTime=True&loc=Local", global.ServerConfig.MysqlInfo.Host)
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags), // io writer
logger.Config{
SlowThreshold: time.Second, // 慢 SQL 阈值
LogLevel: logger.Info, // Log level
Colorful: true, // 禁用彩色打印
},
)
// 全局模式
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true,
},
Logger: newLogger,
})
if err != nil {
panic(err)
}
host := fmt.Sprintf("http://%s:%d", global.ServerConfig.EsInfo.Host, global.ServerConfig.EsInfo.Port)
loggerEs := log.New(os.Stdout, "mxshop", log.LstdFlags)
global.EsClient, err = elastic.NewClient(elastic.SetURL(host), elastic.SetSniff(false),
elastic.SetTraceLog(loggerEs))
if err != nil {
panic(err)
}
var goods []model.Goods
db.Find(&goods)
for _, g := range goods {
esModel := model.EsGoods{
ID: g.ID,
CategoryID: g.CategoryID,
BrandsID: g.BrandsID,
OnSale: g.OnSale,
ShipFree: g.ShipFree,
IsNew: g.IsNew,
IsHot: g.IsHot,
Name: g.Name,
ClickNum: g.ClickNum,
SoldNum: g.SoldNum,
FavNum: g.FavNum,
MarketPrice: g.MarketPrice,
GoodsBrief: g.GoodsBrief,
ShopPrice: g.ShopPrice,
}
_, err = global.EsClient.Index().
Index(esModel.GetIndexName()).
BodyJson(esModel).
Id(strconv.Itoa(int(g.ID))).
Do(context.Background())
if err != nil {
panic(err)
}
//强调一下 一定要将docker启动es的java_ops的内存设置大一些 否则运行过程中会出现 bad request错误
}
}


func (s *GoodsServer) GoodsList(ctx context.Context, req *proto.GoodsFilterRequest) (*proto.GoodsListResponse, error) {
//关键词搜索、查询新品、查询热门商品、通过价格区间筛选, 通过商品分类筛选
goodsListResponse := &proto.GoodsListResponse{}
//match bool 复合查询
q := elastic.NewBoolQuery()
localDB := global.DB.Model(model.Goods{})
if req.KeyWords != "" {
q = q.Must(elastic.NewMultiMatchQuery(req.KeyWords, "name", "goods_brief"))
}
if req.IsHot {
localDB = localDB.Where(model.Goods{IsHot: true})
q = q.Filter(elastic.NewTermQuery("is_hot", req.IsHot))
}
if req.IsNew {
q = q.Filter(elastic.NewTermQuery("is_new", req.IsNew))
}
if req.PriceMin > 0 {
q = q.Filter(elastic.NewRangeQuery("shop_price").Gte(req.PriceMin))
}
if req.PriceMax > 0 {
q = q.Filter(elastic.NewRangeQuery("shop_price").Lte(req.PriceMax))
}
if req.Brand > 0 {
q = q.Filter(elastic.NewTermQuery("brands_id", req.Brand))
}
//通过category去查询商品
// 子查询 嵌套 子查询
// SELECT * FROM goods WHERE category_id IN(SELECT id FROM category WHERE parent_category_id IN (SELECT id FROM category WHERE parent_category_id=1001))
var subQuery string
categoryIds := make([]interface{}, 0)
if req.TopCategory > 0 {
var category model.Category
if result := global.DB.First(&category, req.TopCategory); result.RowsAffected == 0 {
return nil, status.Errorf(codes.NotFound, "商品分类不存在")
}
if category.Level == 1 {
subQuery = fmt.Sprintf("select id from category where parent_category_id in (select id from category WHERE parent_category_id=%d)", req.TopCategory)
} else if category.Level == 2 {
subQuery = fmt.Sprintf("select id from category WHERE parent_category_id=%d", req.TopCategory)
} else if category.Level == 3 {
subQuery = fmt.Sprintf("select id from category WHERE id=%d", req.TopCategory)
}
type Result struct {
ID int32
}
var results []Result
global.DB.Model(model.Category{}).Raw(subQuery).Scan(&results)
for _, re := range results {
categoryIds = append(categoryIds, re.ID)
}
//生成terms查询
q = q.Filter(elastic.NewTermsQuery("category_id", categoryIds...))
}
//分页
if req.Pages == 0 {
req.Pages = 1
}
switch {
case req.PagePerNums > 100:
req.PagePerNums = 100
case req.PagePerNums <= 0:
req.PagePerNums = 10
}
result, err := global.EsClient.Search().Index(model.EsGoods{}.GetIndexName()).Query(q).From(int(req.Pages)).Size(int(req.PagePerNums)).Do(context.Background())
if err != nil {
return nil, err
}
goodsIds := make([]int32, 0)
goodsListResponse.Total = int32(result.Hits.TotalHits.Value)
for _, value := range result.Hits.Hits {
goods := model.EsGoods{}
_ = json.Unmarshal(value.Source, &goods)
goodsIds = append(goodsIds, goods.ID)
}
//查询id在某个数组中的值
var goods []model.Goods
re := localDB.Preload("Category").Preload("Brands").Find(&goods, goodsIds)
if re.Error != nil {
return nil, re.Error
}
for _, good := range goods {
goodsInfoResponse := ModelToResponse(good)
goodsListResponse.Data = append(goodsListResponse.Data, &goodsInfoResponse)
}
return goodsListResponse, nil
}
func (g *Goods) AfterCreate(tx *gorm.DB) (err error) {
esModel := EsGoods{
ID: g.ID,
CategoryID: g.CategoryID,
BrandsID: g.BrandsID,
OnSale: g.OnSale,
ShipFree: g.ShipFree,
IsNew: g.IsNew,
IsHot: g.IsHot,
Name: g.Name,
ClickNum: g.ClickNum,
SoldNum: g.SoldNum,
FavNum: g.FavNum,
MarketPrice: g.MarketPrice,
GoodsBrief: g.GoodsBrief,
ShopPrice: g.ShopPrice,
}
_, err = global.EsClient.Index().Index(esModel.GetIndexName()).BodyJson(esModel).Id(strconv.Itoa(int(g.ID))).Do(context.Background())
if err != nil {
return err
}
return nil
}
func (s *GoodsServer) CreateGoods(ctx context.Context, req *proto.CreateGoodsInfo) (*proto.GoodsInfoResponse, error) {
//省略。。。
//srv之间互相调用了
tx := global.DB.Begin()
result := tx.Save(&goods) // Save的时候会自动调用钩子函数,所以在这里添加事务处理
if result.Error != nil {
tx.Rollback()
return nil, result.Error
}
tx.Commit()
return &proto.GoodsInfoResponse{
Id: goods.ID,
}, nil
}


func (g *Goods) AfterUpdate(tx *gorm.DB) (err error) {
esModel := EsGoods{
ID: g.ID,
CategoryID: g.CategoryID,
BrandsID: g.BrandsID,
OnSale: g.OnSale,
ShipFree: g.ShipFree,
IsNew: g.IsNew,
IsHot: g.IsHot,
Name: g.Name,
ClickNum: g.ClickNum,
SoldNum: g.SoldNum,
FavNum: g.FavNum,
MarketPrice: g.MarketPrice,
GoodsBrief: g.GoodsBrief,
ShopPrice: g.ShopPrice,
}
_, err = global.EsClient.Update().Index(esModel.GetIndexName()).
Doc(esModel).Id(strconv.Itoa(int(g.ID))).Do(context.Background())
if err != nil {
return err
}
return nil
}
func (g *Goods) AfterDelete(tx *gorm.DB) (err error) {
_, err = global.EsClient.Delete().Index(EsGoods{}.GetIndexName()).Id(strconv.Itoa(int(g.ID))).Do(context.Background())
if err != nil {
return err
}
return nil
}
// DeleteGoods 逻辑删除
func (s *GoodsServer) DeleteGoods(ctx context.Context, req *proto.DeleteGoodsInfo) (*emptypb.Empty, error) {
if result := global.DB.Delete(&model.Goods{BaseModel: model.BaseModel{ID: req.Id}}, req.Id); result.Error != nil {
return nil, status.Errorf(codes.NotFound, "商品不存在")
}
return &emptypb.Empty{}, nil
}
func (s *GoodsServer) UpdateGoods(ctx context.Context, req *proto.CreateGoodsInfo) (*emptypb.Empty, error) {
var goods model.Goods
if result := global.DB.First(&goods, req.Id); result.RowsAffected == 0 {
return nil, status.Errorf(codes.NotFound, "商品不存在")
}
var category model.Category
if result := global.DB.First(&category, req.CategoryId); result.RowsAffected == 0 {
return nil, status.Errorf(codes.InvalidArgument, "商品分类不存在")
}
var brand model.Brands
if result := global.DB.First(&brand, req.BrandId); result.RowsAffected == 0 {
return nil, status.Errorf(codes.InvalidArgument, "品牌不存在")
}
goods.Brands = brand
goods.BrandsID = brand.ID
goods.Category = category
goods.CategoryID = category.ID
goods.Name = req.Name
goods.GoodsSn = req.GoodsSn
goods.MarketPrice = req.MarketPrice
goods.ShopPrice = req.ShopPrice
goods.GoodsBrief = req.GoodsBrief
goods.ShipFree = req.ShipFree
goods.Images = req.Images
goods.DescImages = req.DescImages
goods.GoodsFrontImage = req.GoodsFrontImage
goods.IsNew = req.IsNew
goods.IsHot = req.IsHot
goods.OnSale = req.OnSale
tx := global.DB.Begin()
result := tx.Save(&goods)
if result.Error != nil {
tx.Rollback()
return nil, result.Error
}
tx.Commit()
return &emptypb.Empty{}, nil
}
如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby
我在我的Rails项目中使用Pow和powifygem。现在我尝试升级我的ruby版本(从1.9.3到2.0.0,我使用RVM)当我切换ruby版本、安装所有gem依赖项时,我通过运行railss并访问localhost:3000确保该应用程序正常运行以前,我通过使用pow访问http://my_app.dev来浏览我的应用程序。升级后,由于错误Bundler::RubyVersionMismatch:YourRubyversionis1.9.3,butyourGemfilespecified2.0.0,此url不起作用我尝试过的:重新创建pow应用程序重启pow服务器更新战俘
我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="
我在app/helpers/sessions_helper.rb中有一个帮助程序文件,其中包含一个方法my_preference,它返回当前登录用户的首选项。我想在集成测试中访问该方法。例如,这样我就可以在测试中使用getuser_path(my_preference)。在其他帖子中,我读到这可以通过在测试文件中包含requiresessions_helper来实现,但我仍然收到错误NameError:undefinedlocalvariableormethod'my_preference'.我做错了什么?require'test_helper'require'sessions_hel
我一直很高兴地使用DelayedJob习惯用法:foo.send_later(:bar)这会调用DelayedJob进程中对象foo的方法bar。我一直在使用DaemonSpawn在我的服务器上启动DelayedJob进程。但是...如果foo抛出异常,Hoptoad不会捕获它。这是任何这些包中的错误...还是我需要更改某些配置...或者我是否需要在DS或DJ中插入一些异常处理来调用Hoptoad通知程序?回应下面的第一条评论。classDelayedJobWorker 最佳答案 尝试monkeypatchingDelayed::W
假设我有这个范围:("aaaaa".."zzzzz")如何在不事先/每次生成整个项目的情况下从范围中获取第N个项目? 最佳答案 一种快速简便的方法:("aaaaa".."zzzzz").first(42).last#==>"aaabp"如果出于某种原因你不得不一遍又一遍地这样做,或者如果你需要避免为前N个元素构建中间数组,你可以这样写:moduleEnumerabledefskip(n)returnto_enum:skip,nunlessblock_given?each_with_indexdo|item,index|yieldit
文章目录一、概述简介原理模块二、配置Mysql使用版本环境要求1.操作系统2.mysql要求三、配置canal-server离线下载在线下载上传解压修改配置单机配置集群配置分库分表配置1.修改全局配置2.实例配置垂直分库水平分库3.修改group-instance.xml4.启动监听四、配置canal-adapter1修改启动配置2配置映射文件3启动ES数据同步查询所有订阅同步数据同步开关启动4.验证五、配置canal-admin一、概述简介canal是Alibaba旗下的一款开源项目,Java开发。基于数据库增量日志解析,提供增量数据订阅&消费。Git地址:https://github.co
前置步骤我们都操作完了,这篇开始介绍jenkins的集成。话不多说,看操作1、登录进入jenkins后会让你选择安装插件,选择第一个默认的就行。安装完成后设置账号密码,重新登录。2、配置JDK和Git都需要执行路径,所以需要先把执行路径找到,先进入服务器的docker容器,2.1JDK的路径root@69eef9ee86cf:/usr/bin#echo$JAVA_HOME/usr/local/openjdk-82.2Git的路径root@69eef9ee86cf:/#whichgit/usr/bin/git3、先配置JDK和Git。点击:ManageJenkins>>GlobalToolCon
ES一、简介1、ElasticStackES技术栈:ElasticSearch:存数据+搜索;QL;Kibana:Web可视化平台,分析。LogStash:日志收集,Log4j:产生日志;log.info(xxx)。。。。使用场景:metrics:指标监控…2、基本概念Index(索引)动词:保存(插入)名词:类似MySQL数据库,给数据Type(类型)已废弃,以前类似MySQL的表现在用索引对数据分类Document(文档)真正要保存的一个JSON数据{name:"tcx"}二、入门实战{"name":"DESKTOP-1TSVGKG","cluster_name":"elasticsear
1.在Python3中,下列关于数学运算结果正确的是:(B)a=10b=3print(a//b)print(a%b)print(a/b)A.3,3,3.3333...B.3,1,3.3333...C.3.3333...,3.3333...,3D.3.3333...,1,3.3333...解析: 在Python中,//表示地板除(向下取整),%表示取余,/表示除(Python2向下取整返回3)2.如下程序Python2会打印多少个数:(D)k=1000whilek>1: print(k)k=k/2A.1000 B.10C.11D.9解析: 按照题意每次循环K/2,直到K值小于等