Documentation ¶
Overview ¶
Example ¶
spaceNo := uint32(512) indexNo := uint32(0) server := "127.0.0.1:3013" opts := tarantool.Opts{ Timeout: 50 * time.Millisecond, Reconnect: 100 * time.Millisecond, MaxReconnects: 3, User: "test", Pass: "test", } client, err := tarantool.Connect(server, opts) if err != nil { fmt.Errorf("Failed to connect: %s", err.Error()) return } resp, err := client.Ping() fmt.Println("Ping Code", resp.Code) fmt.Println("Ping Data", resp.Data) fmt.Println("Ping Error", err) // delete tuple for cleaning client.Delete(spaceNo, indexNo, []interface{}{uint(10)}) client.Delete(spaceNo, indexNo, []interface{}{uint(11)}) // insert new tuple { 10, 1 } resp, err = client.Insert(spaceNo, []interface{}{uint(10), "test", "one"}) fmt.Println("Insert Error", err) fmt.Println("Insert Code", resp.Code) fmt.Println("Insert Data", resp.Data) // insert new tuple { 11, 1 } resp, err = client.Insert("test", &Tuple{Id: 10, Msg: "test", Name: "one"}) fmt.Println("Insert Error", err) fmt.Println("Insert Code", resp.Code) fmt.Println("Insert Data", resp.Data) // delete tuple with primary key { 10 } resp, err = client.Delete(spaceNo, indexNo, []interface{}{uint(10)}) // or // resp, err = client.Delete("test", "primary", UintKey{10}}) fmt.Println("Delete Error", err) fmt.Println("Delete Code", resp.Code) fmt.Println("Delete Data", resp.Data) // replace tuple with primary key 13 // note, Tuple is defined within tests, and has EncdodeMsgpack and DecodeMsgpack // methods resp, err = client.Replace(spaceNo, []interface{}{uint(13), uint(1)}) fmt.Println("Replace Error", err) fmt.Println("Replace Code", resp.Code) fmt.Println("Replace Data", resp.Data) // update tuple with primary key { 13 }, incrementing second field by 3 resp, err = client.Update("test", "primary", []interface{}{uint(13)}, []tarantool.Op{{"+", 1, 3}}) // or // resp, err = client.Update(spaceNo, indexNo, []interface{}{uint(13)}, []interface{}{[]interface{}{"+", 1, 3}}) fmt.Println("Update Error", err) fmt.Println("Update Code", resp.Code) fmt.Println("Update Data", resp.Data) // select just one tuple with primay key { 15 } resp, err = client.Select(spaceNo, indexNo, 0, 1, tarantool.IterEq, []interface{}{uint(15)}) // or // resp, err = client.Select("test", "primary", 0, 1, tarantool.IterEq, tarantool.UintKey{15}) fmt.Println("Select Error", err) fmt.Println("Select Code", resp.Code) fmt.Println("Select Data", resp.Data) // call function 'func_name' with arguments resp, err = client.Call17("simple_incr", []interface{}{1}) fmt.Println("Call17 Error", err) fmt.Println("Call17 Code", resp.Code) fmt.Println("Call17 Data", resp.Data) // run raw lua code resp, err = client.Eval("return 1 + 2", []interface{}{}) fmt.Println("Eval Error", err) fmt.Println("Eval Code", resp.Code) fmt.Println("Eval Data", resp.Data) resp, err = client.Replace("test", &Tuple{Id: 11, Msg: "test", Name: "eleven"}) resp, err = client.Replace("test", &Tuple{Id: 12, Msg: "test", Name: "twelve"}) var futs [3]*tarantool.Future futs[0] = client.SelectAsync("test", "primary", 0, 2, tarantool.IterLe, []interface{}{uint(12)}) futs[1] = client.SelectAsync("test", "primary", 0, 1, tarantool.IterEq, []interface{}{uint(13)}) futs[2] = client.SelectAsync("test", "primary", 0, 1, tarantool.IterEq, []interface{}{uint(15)}) var t []Tuple err = futs[0].GetTyped(&t) fmt.Println("Fut", 0, "Error", err) fmt.Println("Fut", 0, "Data", t) resp, err = futs[1].Get() fmt.Println("Fut", 1, "Error", err) fmt.Println("Fut", 1, "Data", resp.Data) resp, err = futs[2].Get() fmt.Println("Fut", 2, "Error", err) fmt.Println("Fut", 2, "Data", resp.Data)
Output: Ping Code 0 Ping Data [] Ping Error <nil> Insert Error <nil> Insert Code 0 Insert Data [[10 test one]] Insert Error Duplicate key exists in unique index 'primary' in space 'test' (0x3) Insert Code 3 Insert Data [] Delete Error <nil> Delete Code 0 Delete Data [[10 test one]] Replace Error <nil> Replace Code 0 Replace Data [[13 1]] Update Error <nil> Update Code 0 Update Data [[13 4]] Select Error <nil> Select Code 0 Select Data [[15 val 15 bla]] Call17 Error <nil> Call17 Code 0 Call17 Data [2] Eval Error <nil> Eval Code 0 Eval Data [3] Fut 0 Error <nil> Fut 0 Data [{{} 12 test twelve} {{} 11 test eleven}] Fut 1 Error <nil> Fut 1 Data [[13 4]] Fut 2 Error <nil> Fut 2 Data [[15 val 15 bla]]
Index ¶
- Constants
- func ToUint32(v interface{}) uint32
- type ClientError
- type ConnEvent
- type ConnEventKind
- type ConnLogKind
- type Connection
- func (conn *Connection) Addr() string
- func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error)
- func (conn *Connection) Call17(functionName string, args interface{}) (resp *Response, err error)
- func (conn *Connection) Call17Async(functionName string, args interface{}) *Future
- func (conn *Connection) Call17Typed(functionName string, args interface{}, result interface{}) (err error)
- func (conn *Connection) CallAsync(functionName string, args interface{}) *Future
- func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error)
- func (conn *Connection) Close() error
- func (conn *Connection) ClosedNow() bool
- func (conn *Connection) ConfiguredTimeout() time.Duration
- func (conn *Connection) ConnectedNow() bool
- func (conn *Connection) Delete(space, index interface{}, key interface{}) (resp *Response, err error)
- func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future
- func (conn *Connection) DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
- func (conn *Connection) Eval(expr string, args interface{}) (resp *Response, err error)
- func (conn *Connection) EvalAsync(expr string, args interface{}) *Future
- func (conn *Connection) EvalTyped(expr string, args interface{}, result interface{}) (err error)
- func (conn *Connection) GetTyped(space, index interface{}, key interface{}, result interface{}) (err error)
- func (conn *Connection) Handle() interface{}
- func (conn *Connection) Insert(space interface{}, tuple interface{}) (resp *Response, err error)
- func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Future
- func (conn *Connection) InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error)
- func (conn *Connection) LocalAddr() string
- func (conn *Connection) OverrideSchema(s *Schema)
- func (conn *Connection) Ping() (resp *Response, err error)
- func (conn *Connection) RemoteAddr() string
- func (conn *Connection) Replace(space interface{}, tuple interface{}) (resp *Response, err error)
- func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Future
- func (conn *Connection) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error)
- func (conn *Connection) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *Response, err error)
- func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future
- func (conn *Connection) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, ...) (err error)
- func (conn *Connection) Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
- func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface{}) *Future
- func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
- func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
- func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future
- type Connector
- type DeadlineIO
- type Error
- type Field
- type Future
- type Greeting
- type Index
- type IndexField
- type IntIntKey
- type IntKey
- type Logger
- type Op
- type OpSplice
- type Opts
- type Response
- type Schema
- type Space
- type StringKey
- type UintKey
Examples ¶
Constants ¶
const ( // Connect signals that connection is established or reestablished Connected ConnEventKind = iota + 1 // Disconnect signals that connection is broken Disconnected // ReconnectFailed signals that attempt to reconnect has failed ReconnectFailed // Either reconnect attempts exhausted, or explicit Close is called Closed // LogReconnectFailed is logged when reconnect attempt failed LogReconnectFailed ConnLogKind = iota + 1 // LogLastReconnectFailed is logged when last reconnect attempt failed, // connection will be closed after that. LogLastReconnectFailed // LogUnexpectedResultId is logged when response with unknown id were received. // Most probably it is due to request timeout. LogUnexpectedResultId )
const ( SelectRequest = 1 InsertRequest = 2 ReplaceRequest = 3 UpdateRequest = 4 DeleteRequest = 5 CallRequest = 6 /* call in 1.6 format */ AuthRequest = 7 EvalRequest = 8 UpsertRequest = 9 Call17Request = 10 PingRequest = 64 SubscribeRequest = 66 KeyCode = 0x00 KeySync = 0x01 KeySpaceNo = 0x10 KeyIndexNo = 0x11 KeyLimit = 0x12 KeyOffset = 0x13 KeyIterator = 0x14 KeyKey = 0x20 KeyTuple = 0x21 KeyFunctionName = 0x22 KeyUserName = 0x23 KeyExpression = 0x27 KeyDefTuple = 0x28 KeyData = 0x30 KeyError = 0x31 IterEq = uint32(0) // key == x ASC order IterReq = uint32(1) // key == x DESC order IterAll = uint32(2) // all tuples IterLt = uint32(3) // key < x IterLe = uint32(4) // key <= x IterGe = uint32(5) // key >= x IterGt = uint32(6) // key > x IterBitsAllSet = uint32(7) // all bits from x are set in key IterBitsAnySet = uint32(8) // at least one x's bit is set IterBitsAllNotSet = uint32(9) // all bits are not set RLimitDrop = 1 RLimitWait = 2 OkCode = uint32(0) ErrorCodeBit = 0x8000 PacketLengthBytes = 5 )
const ( ErrConnectionNotReady = 0x4000 + iota ErrConnectionClosed = 0x4000 + iota ErrProtocolError = 0x4000 + iota ErrTimeouted = 0x4000 + iota ErrRateLimited = 0x4000 + iota )
Tarantool client error codes
const ( ErrUnknown = 0 // Unknown error ErrIllegalParams = 1 // Illegal parameters, %s ErrMemoryIssue = 2 // Failed to allocate %u bytes in %s for %s ErrTupleFound = 3 // Duplicate key exists in unique index '%s' in space '%s' ErrTupleNotFound = 4 // Tuple doesn't exist in index '%s' in space '%s' ErrUnsupported = 5 // %s does not support %s ErrNonmaster = 6 // Can't modify data on a replication slave. My master is: %s ErrReadonly = 7 // Can't modify data because this server is in read-only mode. ErrInjection = 8 // Error injection '%s' ErrCreateSpace = 9 // Failed to create space '%s': %s ErrSpaceExists = 10 // Space '%s' already exists ErrDropSpace = 11 // Can't drop space '%s': %s ErrAlterSpace = 12 // Can't modify space '%s': %s ErrIndexType = 13 // Unsupported index type supplied for index '%s' in space '%s' ErrModifyIndex = 14 // Can't create or modify index '%s' in space '%s': %s ErrLastDrop = 15 // Can't drop the primary key in a system space, space '%s' ErrTupleFormatLimit = 16 // Tuple format limit reached: %u ErrDropPrimaryKey = 17 // Can't drop primary key in space '%s' while secondary keys exist ErrKeyPartType = 18 // Supplied key type of part %u does not match index part type: expected %s ErrExactMatch = 19 // Invalid key part count in an exact match (expected %u, got %u) ErrInvalidMsgpack = 20 // Invalid MsgPack - %s ErrProcRet = 21 // msgpack.encode: can not encode Lua type '%s' ErrTupleNotArray = 22 // Tuple/Key must be MsgPack array ErrFieldType = 23 // Tuple field %u type does not match one required by operation: expected %s ErrFieldTypeMismatch = 24 // Ambiguous field type in index '%s', key part %u. Requested type is %s but the field has previously been defined as %s ErrSplice = 25 // SPLICE error on field %u: %s ErrArgType = 26 // Argument type in operation '%c' on field %u does not match field type: expected a %s ErrTupleIsTooLong = 27 // Tuple is too long %u ErrUnknownUpdateOp = 28 // Unknown UPDATE operation ErrUpdateField = 29 // Field %u UPDATE error: %s ErrFiberStack = 30 // Can not create a new fiber: recursion limit reached ErrKeyPartCount = 31 // Invalid key part count (expected [0..%u], got %u) ErrProcLua = 32 // %s ErrNoSuchProc = 33 // Procedure '%.*s' is not defined ErrNoSuchTrigger = 34 // Trigger is not found ErrNoSuchIndex = 35 // No index #%u is defined in space '%s' ErrNoSuchSpace = 36 // Space '%s' does not exist ErrNoSuchField = 37 // Field %d was not found in the tuple ErrSpaceFieldCount = 38 // Tuple field count %u does not match space '%s' field count %u ErrIndexFieldCount = 39 // Tuple field count %u is less than required by a defined index (expected %u) ErrWalIo = 40 // Failed to write to disk ErrMoreThanOneTuple = 41 // More than one tuple found by get() ErrAccessDenied = 42 // %s access denied for user '%s' ErrCreateUser = 43 // Failed to create user '%s': %s ErrDropUser = 44 // Failed to drop user '%s': %s ErrNoSuchUser = 45 // User '%s' is not found ErrUserExists = 46 // User '%s' already exists ErrPasswordMismatch = 47 // Incorrect password supplied for user '%s' ErrUnknownRequestType = 48 // Unknown request type %u ErrUnknownSchemaObject = 49 // Unknown object type '%s' ErrCreateFunction = 50 // Failed to create function '%s': %s ErrNoSuchFunction = 51 // Function '%s' does not exist ErrFunctionExists = 52 // Function '%s' already exists ErrFunctionAccessDenied = 53 // %s access denied for user '%s' to function '%s' ErrFunctionMax = 54 // A limit on the total number of functions has been reached: %u ErrSpaceAccessDenied = 55 // %s access denied for user '%s' to space '%s' ErrUserMax = 56 // A limit on the total number of users has been reached: %u ErrNoSuchEngine = 57 // Space engine '%s' does not exist ErrReloadCfg = 58 // Can't set option '%s' dynamically ErrCfg = 59 // Incorrect value for option '%s': %s ErrSophia = 60 // %s ErrLocalServerIsNotActive = 61 // Local server is not active ErrUnknownServer = 62 // Server %s is not registered with the cluster ErrClusterIdMismatch = 63 // Cluster id of the replica %s doesn't match cluster id of the master %s ErrInvalidUUID = 64 // Invalid UUID: %s ErrClusterIdIsRo = 65 // Can't reset cluster id: it is already assigned ErrReserved66 = 66 // Reserved66 ErrServerIdIsReserved = 67 // Can't initialize server id with a reserved value %u ErrInvalidOrder = 68 // Invalid LSN order for server %u: previous LSN = %llu, new lsn = %llu ErrMissingRequestField = 69 // Missing mandatory field '%s' in request ErrIdentifier = 70 // Invalid identifier '%s' (expected letters, digits or an underscore) ErrDropFunction = 71 // Can't drop function %u: %s ErrIteratorType = 72 // Unknown iterator type '%s' ErrReplicaMax = 73 // Replica count limit reached: %u ErrInvalidXlog = 74 // Failed to read xlog: %lld ErrInvalidXlogName = 75 // Invalid xlog name: expected %lld got %lld ErrInvalidXlogOrder = 76 // Invalid xlog order: %lld and %lld ErrNoConnection = 77 // Connection is not established ErrTimeout = 78 // Timeout exceeded ErrActiveTransaction = 79 // Operation is not permitted when there is an active transaction ErrNoActiveTransaction = 80 // Operation is not permitted when there is no active transaction ErrCrossEngineTransaction = 81 // A multi-statement transaction can not use multiple storage engines ErrNoSuchRole = 82 // Role '%s' is not found ErrRoleExists = 83 // Role '%s' already exists ErrCreateRole = 84 // Failed to create role '%s': %s ErrIndexExists = 85 // Index '%s' already exists ErrTupleRefOverflow = 86 // Tuple reference counter overflow ErrRoleLoop = 87 // Granting role '%s' to role '%s' would create a loop ErrGrant = 88 // Incorrect grant arguments: %s ErrPrivGranted = 89 // User '%s' already has %s access on %s '%s' ErrRoleGranted = 90 // User '%s' already has role '%s' ErrPrivNotGranted = 91 // User '%s' does not have %s access on %s '%s' ErrRoleNotGranted = 92 // User '%s' does not have role '%s' ErrMissingSnapshot = 93 // Can't find snapshot ErrCantUpdatePrimaryKey = 94 // Attempt to modify a tuple field which is part of index '%s' in space '%s' ErrUpdateIntegerOverflow = 95 // Integer overflow when performing '%c' operation on field %u ErrGuestUserPassword = 96 // Setting password for guest user has no effect ErrTransactionConflict = 97 // Transaction has been aborted by conflict ErrUnsupportedRolePriv = 98 // Unsupported role privilege '%s' ErrLoadFunction = 99 // Failed to dynamically load function '%s': %s ErrFunctionLanguage = 100 // Unsupported language '%s' specified for function '%s' ErrRtreeRect = 101 // RTree: %s must be an array with %u (point) or %u (rectangle/box) numeric coordinates ErrProcC = 102 // ??? ErrUnknownRtreeIndexDistanceType = 103 //Unknown RTREE index distance type %s ErrProtocol = 104 // %s ErrUpsertUniqueSecondaryKey = 105 // Space %s has a unique secondary index and does not support UPSERT ErrWrongIndexRecord = 106 // Wrong record in _index space: got {%s}, expected {%s} ErrWrongIndexParts = 107 // Wrong index parts (field %u): %s; expected field1 id (number), field1 type (string), ... ErrWrongIndexOptions = 108 // Wrong index options (field %u): %s ErrWrongSchemaVaersion = 109 // Wrong schema version, current: %d, in request: %u ErrSlabAllocMax = 110 // Failed to allocate %u bytes for tuple in the slab allocator: tuple is too large. Check 'slab_alloc_maximal' configuration option. )
Tarantool server error codes
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ClientError ¶
ClientError is connection produced by this client, ie connection failures or timeouts.
func (ClientError) Error ¶
func (clierr ClientError) Error() string
func (ClientError) Temporary ¶
func (clierr ClientError) Temporary() bool
Temporary returns true if next attempt to perform request may succeeed. Currently it returns true when: - Connection is not connected at the moment, - or request is timeouted, - or request is aborted due to rate limit.
type ConnEvent ¶
type ConnEvent struct { Conn *Connection Kind ConnEventKind When time.Time }
ConnEvent is sent throw Notify channel specified in Opts
type ConnEventKind ¶
type ConnEventKind int
type ConnLogKind ¶
type ConnLogKind int
type Connection ¶
type Connection struct { // Schema contains schema loaded on connection. Schema *Schema // Greeting contains first message sent by tarantool Greeting *Greeting // contains filtered or unexported fields }
Connection is a handle to Tarantool.
It is created and configured with Connect function, and could not be reconfigured later.
It is could be "Connected", "Disconnected", and "Closed".
When "Connected" it sends queries to Tarantool.
When "Disconnected" it rejects queries with ClientError{Code: ErrConnectionNotReady}
When "Closed" it rejects queries with ClientError{Code: ErrConnectionClosed}
Connection could become "Closed" when Connection.Close() method called, or when Tarantool disconnected and Reconnect pause is not specified or MaxReconnects is specified and MaxReconnect reconnect attempts already performed.
You may perform data manipulation operation by calling its methods: Call*, Insert*, Replace*, Update*, Upsert*, Call*, Eval*.
In any method that accepts `space` you my pass either space number or space name (in this case it will be looked up in schema). Same is true for `index`.
ATTENTION: `tuple`, `key`, `ops` and `args` arguments for any method should be and array or should serialize to msgpack array.
ATTENTION: `result` argument for *Typed methods should deserialize from msgpack array, cause Tarantool always returns result as an array. For all space related methods and Call* (but not Call17*) methods Tarantool always returns array of array (array of tuples for space related methods). For Eval* and Call17* tarantool always returns array, but does not forces array of arrays.
func Connect ¶
func Connect(addr string, opts Opts) (conn *Connection, err error)
Connect creates and configures new Connection
Address could be specified in following ways:
TCP connections: - tcp://192.168.1.1:3013 - tcp://my.host:3013 - tcp:192.168.1.1:3013 - tcp:my.host:3013 - 192.168.1.1:3013 - my.host:3013 Unix socket: - unix:///abs/path/tnt.sock - unix:path/tnt.sock - /abs/path/tnt.sock - first '/' indicates unix socket - ./rel/path/tnt.sock - first '.' indicates unix socket - unix/:path/tnt.sock - 'unix/' acts as a "host" and "/path..." as a port
Note:
- If opts.Reconnect is zero (default), then connection either already connected or error is returned.
- If opts.Reconnect is non-zero, then error will be returned only if authorization// fails. But if Tarantool is not reachable, then it will attempt to reconnect later and will not end attempts on authorization failures.
func (*Connection) Addr ¶
func (conn *Connection) Addr() string
Addr is configured address of Tarantool socket
func (*Connection) Call ¶
func (conn *Connection) Call(functionName string, args interface{}) (resp *Response, err error)
Call calls registered tarantool function. It uses request code for tarantool 1.6, so result is converted to array of arrays
It is equal to conn.CallAsync(functionName, args).Get().
func (*Connection) Call17 ¶
func (conn *Connection) Call17(functionName string, args interface{}) (resp *Response, err error)
Call17 calls registered tarantool function. It uses request code for tarantool 1.7, so result is not converted (though, keep in mind, result is always array)
It is equal to conn.Call17Async(functionName, args).Get().
func (*Connection) Call17Async ¶
func (conn *Connection) Call17Async(functionName string, args interface{}) *Future
Call17Async sends a call to registered tarantool function and returns Future. It uses request code for tarantool 1.7, so future's result will not be converted (though, keep in mind, result is always array)
func (*Connection) Call17Typed ¶
func (conn *Connection) Call17Typed(functionName string, args interface{}, result interface{}) (err error)
Call17Typed calls registered function. It uses request code for tarantool 1.7, so result is not converted (though, keep in mind, result is always array)
It is equal to conn.Call17Async(functionName, args).GetTyped(&result).
func (*Connection) CallAsync ¶
func (conn *Connection) CallAsync(functionName string, args interface{}) *Future
CallAsync sends a call to registered tarantool function and returns Future. It uses request code for tarantool 1.6, so future's result is always array of arrays
func (*Connection) CallTyped ¶
func (conn *Connection) CallTyped(functionName string, args interface{}, result interface{}) (err error)
CallTyped calls registered function. It uses request code for tarantool 1.6, so result is converted to array of arrays
It is equal to conn.CallAsync(functionName, args).GetTyped(&result).
func (*Connection) Close ¶
func (conn *Connection) Close() error
Close closes Connection. After this method called, there is no way to reopen this Connection.
func (*Connection) ClosedNow ¶
func (conn *Connection) ClosedNow() bool
ClosedNow reports if connection is closed by user or after reconnect.
func (*Connection) ConfiguredTimeout ¶
func (conn *Connection) ConfiguredTimeout() time.Duration
ConfiguredTimeout returns timeout from connection config
func (*Connection) ConnectedNow ¶
func (conn *Connection) ConnectedNow() bool
ConnectedNow reports if connection is established at the moment.
func (*Connection) Delete ¶
func (conn *Connection) Delete(space, index interface{}, key interface{}) (resp *Response, err error)
Delete performs deletion of a tuple by key. Result will contain array with deleted tuple.
It is equal to conn.DeleteAsync(space, tuple).Get().
func (*Connection) DeleteAsync ¶
func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future
DeleteAsync sends deletion action to tarantool and returns Future. Future's result will contain array with deleted tuple.
func (*Connection) DeleteTyped ¶
func (conn *Connection) DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error)
DeleteTyped performs deletion of a tuple by key and fills result with deleted tuple.
It is equal to conn.DeleteAsync(space, tuple).GetTyped(&result).
func (*Connection) Eval ¶
func (conn *Connection) Eval(expr string, args interface{}) (resp *Response, err error)
Eval passes lua expression for evaluation.
It is equal to conn.EvalAsync(space, tuple).Get().
func (*Connection) EvalAsync ¶
func (conn *Connection) EvalAsync(expr string, args interface{}) *Future
EvalAsync sends a lua expression for evaluation and returns Future.
func (*Connection) EvalTyped ¶
func (conn *Connection) EvalTyped(expr string, args interface{}, result interface{}) (err error)
EvalTyped passes lua expression for evaluation.
It is equal to conn.EvalAsync(space, tuple).GetTyped(&result).
func (*Connection) GetTyped ¶
func (conn *Connection) GetTyped(space, index interface{}, key interface{}, result interface{}) (err error)
GetTyped performs select (with limit = 1 and offset = 0) to box space and fills typed result.
It is equal to conn.SelectAsync(space, index, 0, 1, IterEq, key).GetTyped(&result)
func (*Connection) Handle ¶
func (conn *Connection) Handle() interface{}
Handle returns user specified handle from Opts
func (*Connection) Insert ¶
func (conn *Connection) Insert(space interface{}, tuple interface{}) (resp *Response, err error)
Insert performs insertion to box space. Tarantool will reject Insert when tuple with same primary key exists.
It is equal to conn.InsertAsync(space, tuple).Get().
func (*Connection) InsertAsync ¶
func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Future
InsertAsync sends insert action to tarantool and returns Future. Tarantool will reject Insert when tuple with same primary key exists.
func (*Connection) InsertTyped ¶
func (conn *Connection) InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error)
InsertTyped performs insertion to box space. Tarantool will reject Insert when tuple with same primary key exists.
It is equal to conn.InsertAsync(space, tuple).GetTyped(&result).
func (*Connection) LocalAddr ¶
func (conn *Connection) LocalAddr() string
LocalAddr is address of outgoing socket
func (*Connection) OverrideSchema ¶
func (conn *Connection) OverrideSchema(s *Schema)
OverrideSchema sets Schema for the connection
func (*Connection) Ping ¶
func (conn *Connection) Ping() (resp *Response, err error)
Ping sends empty request to Tarantool to check connection.
func (*Connection) RemoteAddr ¶
func (conn *Connection) RemoteAddr() string
RemoteAddr is address of Tarantool socket
func (*Connection) Replace ¶
func (conn *Connection) Replace(space interface{}, tuple interface{}) (resp *Response, err error)
Replace performs "insert or replace" action to box space. If tuple with same primary key exists, it will be replaced.
It is equal to conn.ReplaceAsync(space, tuple).Get().
func (*Connection) ReplaceAsync ¶
func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Future
ReplaceAsync sends "insert or replace" action to tarantool and returns Future. If tuple with same primary key exists, it will be replaced.
func (*Connection) ReplaceTyped ¶
func (conn *Connection) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error)
ReplaceTyped performs "insert or replace" action to box space. If tuple with same primary key exists, it will be replaced.
It is equal to conn.ReplaceAsync(space, tuple).GetTyped(&result).
func (*Connection) Select ¶
func (conn *Connection) Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *Response, err error)
Select performs select to box space.
It is equal to conn.SelectAsync(...).Get()
Example ¶
var conn *tarantool.Connection conn, err := example_connect() if err != nil { fmt.Printf("error in prepare is %v", err) return } defer conn.Close() resp, err := conn.Select(512, 0, 0, 100, tarantool.IterEq, []interface{}{uint(1111)}) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %#v\n", resp.Data) resp, err = conn.Select("test", "primary", 0, 100, tarantool.IterEq, []interface{}{uint(1111)}) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %#v\n", resp.Data)
Output: response is []interface {}{[]interface {}{0x457, "hello", "world"}} response is []interface {}{[]interface {}{0x457, "hello", "world"}}
func (*Connection) SelectAsync ¶
func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future
SelectAsync sends select request to tarantool and returns Future.
func (*Connection) SelectTyped ¶
func (conn *Connection) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) (err error)
SelectTyped performs select to box space and fills typed result.
It is equal to conn.SelectAsync(space, index, offset, limit, iterator, key).GetTyped(&result)
Example ¶
var conn *tarantool.Connection conn, err := example_connect() if err != nil { fmt.Printf("error in prepare is %v", err) return } defer conn.Close() var res []Tuple err = conn.SelectTyped(512, 0, 0, 100, tarantool.IterEq, []interface{}{uint(1111)}, &res) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %v\n", res) err = conn.SelectTyped("test", "primary", 0, 100, tarantool.IterEq, []interface{}{uint(1111)}, &res) if err != nil { fmt.Printf("error in select is %v", err) return } fmt.Printf("response is %v\n", res)
Output: response is [{{} 1111 hello world}] response is [{{} 1111 hello world}]
func (*Connection) Update ¶
func (conn *Connection) Update(space, index interface{}, key, ops interface{}) (resp *Response, err error)
Update performs update of a tuple by key. Result will contain array with updated tuple.
It is equal to conn.UpdateAsync(space, tuple).Get().
func (*Connection) UpdateAsync ¶
func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface{}) *Future
Update sends deletion of a tuple by key and returns Future. Future's result will contain array with updated tuple.
func (*Connection) UpdateTyped ¶
func (conn *Connection) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error)
UpdateTyped performs update of a tuple by key and fills result with updated tuple.
It is equal to conn.UpdateAsync(space, tuple, ops).GetTyped(&result).
func (*Connection) Upsert ¶
func (conn *Connection) Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error)
Upsert performs "update or insert" action of a tuple by key. Result will not contain any tuple.
It is equal to conn.UpsertAsync(space, tuple, ops).Get().
func (*Connection) UpsertAsync ¶
func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future
UpsertAsync sends "update or insert" action to tarantool and returns Future. Future's sesult will not contain any tuple.
type Connector ¶
type Connector interface { ConnectedNow() bool Close() error Ping() (resp *Response, err error) ConfiguredTimeout() time.Duration Select(space, index interface{}, offset, limit, iterator uint32, key interface{}) (resp *Response, err error) Insert(space interface{}, tuple interface{}) (resp *Response, err error) Replace(space interface{}, tuple interface{}) (resp *Response, err error) Delete(space, index interface{}, key interface{}) (resp *Response, err error) Update(space, index interface{}, key, ops interface{}) (resp *Response, err error) Upsert(space interface{}, tuple, ops interface{}) (resp *Response, err error) Call(functionName string, args interface{}) (resp *Response, err error) Call17(functionName string, args interface{}) (resp *Response, err error) Eval(expr string, args interface{}) (resp *Response, err error) GetTyped(space, index interface{}, key interface{}, result interface{}) (err error) SelectTyped(space, index interface{}, offset, limit, iterator uint32, key interface{}, result interface{}) (err error) InsertTyped(space interface{}, tuple interface{}, result interface{}) (err error) ReplaceTyped(space interface{}, tuple interface{}, result interface{}) (err error) DeleteTyped(space, index interface{}, key interface{}, result interface{}) (err error) UpdateTyped(space, index interface{}, key, ops interface{}, result interface{}) (err error) CallTyped(functionName string, args interface{}, result interface{}) (err error) Call17Typed(functionName string, args interface{}, result interface{}) (err error) EvalTyped(expr string, args interface{}, result interface{}) (err error) SelectAsync(space, index interface{}, offset, limit, iterator uint32, key interface{}) *Future InsertAsync(space interface{}, tuple interface{}) *Future ReplaceAsync(space interface{}, tuple interface{}) *Future DeleteAsync(space, index interface{}, key interface{}) *Future UpdateAsync(space, index interface{}, key, ops interface{}) *Future UpsertAsync(space interface{}, tuple interface{}, ops interface{}) *Future CallAsync(functionName string, args interface{}) *Future Call17Async(functionName string, args interface{}) *Future EvalAsync(expr string, args interface{}) *Future }
type DeadlineIO ¶
type DeadlineIO struct {
// contains filtered or unexported fields
}
type Future ¶
type Future struct {
// contains filtered or unexported fields
}
Future is a handle for asynchronous request
func (*Future) Get ¶
Get waits for Future to be filled and returns Response and error
Response will contain deserialized result in Data field. It will be []interface{}, so if you want more performace, use GetTyped method.
Note: Response could be equal to nil if ClientError is returned in error.
"error" could be Error, if it is error returned by Tarantool, or ClientError, if something bad happens in a client process.
type Greeting ¶
type Greeting struct { Version string // contains filtered or unexported fields }
Greeting is a message sent by tarantool on connect.
type Index ¶
type Index struct { Id uint32 Name string Type string Unique bool Fields []*IndexField }
Index contains information about index
type IndexField ¶
type IntIntKey ¶
type IntIntKey struct {
I1, I2 int
}
IntIntKey is utility type for passing two integer keys to Select*, Update* and Delete* It serializes to array with two integer elements
type IntKey ¶
type IntKey struct {
I int
}
IntKey is utility type for passing integer key to Select*, Update* and Delete* It serializes to array with single integer element.
type Logger ¶
type Logger interface {
Report(event ConnLogKind, conn *Connection, v ...interface{})
}
Logger is logger type expected to be passed in options.
type Opts ¶
type Opts struct { // Timeout is requests timeout. // Also used to setup net.TCPConn.Set(Read|Write)Deadline Timeout time.Duration // Reconnect is a pause between reconnection attempts. // If specified, then when tarantool is not reachable or disconnected, // new connect attempt is performed after pause. // By default, no reconnection attempts are performed, // so once disconnected, connection becomes Closed. Reconnect time.Duration // MaxReconnects is a maximum reconnect attempts. // After MaxReconnects attempts Connection becomes closed. MaxReconnects uint // User name for authorization User string // Pass is password for authorization Pass string // RateLimit limits number of 'in-fly' request, ie already putted into // requests queue, but not yet answered by server or time-outed. // It is disabled by default. // See RLimitAction for possible actions when RateLimit.reached. RateLimit uint // RLimitAction tells what to do when RateLimit reached: // RLimitDrop - immediately abort request, // RLimitWait - wait during timeout period for some request to be answered. // If no request answered during timeout period, this request // is aborted. // If no timeout period is set, it will wait forever. // It is required if RateLimit is specified. RLimitAction uint // Concurrency is amount of separate mutexes for request // queues and buffers inside of connection. // It is rounded upto nearest power of 2. // By default it is runtime.GOMAXPROCS(-1) * 4 Concurrency uint32 // SkipSchema disables schema loading. Without disabling schema loading, // there is no way to create Connection for currently not accessible tarantool. SkipSchema bool // Notify is a channel which receives notifications about Connection status // changes. Notify chan<- ConnEvent // Handle is user specified value, that could be retrieved with Handle() method Handle interface{} // Logger is user specified logger used for error messages Logger Logger // EncoderFunc is optional parameter to configure creation of msgpack encoder. EncoderFunc func(w io.Writer) *msgpack.Encoder // DecoderFunc is optional parameter to configure creation of msgpack decoder. DecoderFunc func(r io.Reader) *msgpack.Decoder }
Opts is a way to configure Connection
type Response ¶
type Response struct { RequestId uint32 Code uint32 Error string // error message // Data contains deserialized data for untyped requests Data []interface{} // contains filtered or unexported fields }
type Schema ¶
type Schema struct { Version uint // Spaces is map from space names to spaces Spaces map[string]*Space // SpacesById is map from space numbers to spaces SpacesById map[uint32]*Space }
Schema contains information about spaces and indexes.
type Space ¶
type Space struct { Id uint32 Name string Engine string Temporary bool // Is this space temporaray? // Field configuration is not mandatory and not checked by tarantool. FieldsCount uint32 Fields map[string]*Field FieldsById map[uint32]*Field // Indexes is map from index names to indexes Indexes map[string]*Index // IndexesById is map from index numbers to indexes IndexesById map[uint32]*Index }
Space contains information about tarantool space