英文:
tarantool queue attempt to index global 'queue'
问题
-
我在以下代码的一行中遇到了错误:
que := queue.New(conn, "foobar")
错误信息为:Error eval:1: attempt to index global 'queue' (a nil value) (0x20) -
配置文件如下(如果我删除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()
}
英文:
-
I have error in line:
que := queue.New(conn, "foobar")
: Error eval:1: attempt to index global 'queue' (a nil value) (0x20) -
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论