tarantool队列尝试索引全局变量’queue’。

huangapple go评论96阅读模式
英文:

tarantool queue attempt to index global 'queue'

问题

  1. 我在以下代码的一行中遇到了错误:
    que := queue.New(conn, "foobar")
    错误信息为:Error eval:1: attempt to index global 'queue' (a nil value) (0x20)

  2. 配置文件如下(如果我删除box.once,那么tube错误就存在了):
    如何在配置文件中正确初始化用户和tube,而不出现“用户已存在”的错误?

box.cfg {listen=3303}
local queue = require('queue')
queue.start()
queue.create_tube('foobar', 'fifottl', {if_not_exists=true})
box.once("init", function()
    box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

代码如下:

func TestTarantoolQueue(t *testing.T)  {
    //opts := tarantool.Opts{User: "test", Pass: "test"}
    opts := tarantool.Opts{}
    conn, err := tarantool.Connect("127.0.0.1:3303", opts)
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    cfg := queue.Cfg{
        Temporary: true,
        IfNotExists: true,
        Kind: queue.FIFO_TTL,
        Opts: queue.Opts{
            Ttl: 10 * time.Second,
            Ttr: 5 * time.Second,
            Delay: 3 * time.Second,
            Pri: 1,
        },
    }
    que := queue.New(conn, "foobar")
    err = que.Create(cfg)
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    task, err := que.Put("test_data")
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    fmt.Println("Task id is ", task.Id())
    task, err = que.Take() //blocking operation
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    fmt.Println("Data is ", task.Data())
    task.Ack()
    task, err = que.Put([]int{1, 2, 3})
    if err != nil {
        t.Log("Error", err)
        t.FailNow()
    }
    task.Bury()
    task, err = que.TakeTimeout(2 * time.Second)
    if task == nil {
        fmt.Println("Task is nil")
    }
    que.Drop()
}
英文:
  1. I have error in line:
    que := queue.New(conn, "foobar")
    : Error eval:1: attempt to index global 'queue' (a nil value) (0x20)

  2. Config file: (if i delete box.once then erros tube is exists)
    How to correct init users and tube in config, without error 'user already exist`?

`

box.cfg {listen=3303}
local queue = require('queue')
queue.start()
queue.create_tube('foobar', 'fifottl', {if_not_exists=true})
box.once("init", function()
	box.schema.user.grant('guest', 'read,write,execute', 'universe')
end)

`

code:
`

func TestTarantoolQueue(t *testing.T)  {
	//opts := tarantool.Opts{User: "test", Pass: "test"}
	opts := tarantool.Opts{}
	conn, err := tarantool.Connect("127.0.0.1:3303", opts)
	if err != nil {
		t.Log("Error", err)
		t.FailNow()
	}
	cfg := queue.Cfg{
		Temporary: true,
		IfNotExists: true,
		Kind: queue.FIFO_TTL,
		Opts: queue.Opts{
			Ttl: 10 * time.Second,
			Ttr: 5 * time.Second,
			Delay: 3 * time.Second,
			Pri: 1,
		},
	}
	que := queue.New(conn, "foobar")
	err = que.Create(cfg)
	if err != nil {
		t.Log("Error", err)
		t.FailNow()
	}
	task, err := que.Put("test_data")
	if err != nil {
		t.Log("Error", err)
		t.FailNow()
	}
	fmt.Println("Task id is ", task.Id())
	task, err = que.Take() //blocking operation
	if err != nil {
		t.Log("Error", err)
		t.FailNow()
	}
	fmt.Println("Data is ", task.Data())
	task.Ack()
	task, err = que.Put([]int{1, 2, 3})
	if err != nil {
		t.Log("Error", err)
		t.FailNow()
	}
	task.Bury()
	task, err = que.TakeTimeout(2 * time.Second)
	if task == nil {
		fmt.Println("Task is nil")
	}
	que.Drop()
}

`

答案1

得分: 1

local queue = require('queue')中删除local应该可以解决这个问题。

英文:

Removing local from local queue = require('queue') should solve the problem.

huangapple
  • 本文由 发表于 2017年9月14日 20:12:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/46218813.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定