### Install Redigo Source: https://github.com/tidwall/tile38/wiki/Go-Example-(redigo) Use 'go get' to install the redigo Redis client library. ```bash go get github.com/garyburd/redigo/redis ``` -------------------------------- ### Install Tile38 with Homebrew Source: https://github.com/tidwall/tile38/blob/master/README.md Installs Tile38 using Homebrew on macOS and starts the server. ```bash brew install tile38 tile38-server ``` -------------------------------- ### Start Tile38 with Prometheus Metrics Source: https://github.com/tidwall/tile38/blob/master/README.md Starts the Tile38 server and enables Prometheus metrics on a specified address and port. This example listens on the local interface only. ```bash ./tile38-server --metrics-addr=127.0.0.1:4321 ``` -------------------------------- ### Install redis-rb Gem Source: https://github.com/tidwall/tile38/wiki/Ruby-example-(redis-rb) Install the redis-rb gem using the gem command. This is a prerequisite for running the Ruby example. ```bash gem install redis ``` -------------------------------- ### Install go-redis Source: https://github.com/tidwall/tile38/wiki/Go-Example-(go-redis) Installs the go-redis/v8 package. Ensure your Go version supports modules and you have initialized a Go module. ```shell go mod init github.com/my/repo ``` ```shell go get github.com/go-redis/redis/v8 ``` -------------------------------- ### Install redis-py Source: https://github.com/tidwall/tile38/wiki/Python-example Install the redis-py library using pip. This is the first step to using Redis in Python. ```bash pip install redis ``` -------------------------------- ### Install node-tile38 Source: https://github.com/tidwall/tile38/wiki/Node.js-example-(node-tile38) Install the node-tile38 package using npm. ```bash npm install tile38 ``` -------------------------------- ### Build Tile38 from Source Source: https://github.com/tidwall/tile38/blob/master/README.md Compiles the Tile38 project. Requires Go to be installed on the build machine. ```bash make ``` -------------------------------- ### Go Redis Client and Tile38 Commands Source: https://github.com/tidwall/tile38/wiki/Go-Example-(go-redis) Sets up a go-redis client and executes Tile38 SET and GET commands. Use redis.NewStringCmd for query composition, Process to execute, and Result to get the query outcome. ```go import ( "context" "log" "github.com/go-redis/redis/v8" ) func main() { // Tile38 Client Setup var ctx = context.Background() client := redis.NewClient(&redis.Options{ Addr: "127.0.0.1:9851", }) // SET setCmd := redis.NewStringCmd(ctx, "SET", "fleet", "truck", "POINT", 33.32, 115.423) if err := client.Process(ctx, setCmd); err != nil { log.Fatalf("SET command execution failed: %v", err) } setRes, err := setCmd.Result() if err != nil { log.Fatalf("Failed to retrieve SET result: %v", err) } log.Printf("SET: %s", setRes) // GET getCmd := redis.NewStringCmd(ctx, "GET", "fleet", "truck") if err := client.Process(ctx, getCmd); err != nil { log.Fatalf("GET command execution failed: %v", err) } getRes, err := getCmd.Result() if err != nil { log.Fatalf("Failed to retrieve GET result: %v", err) } log.Printf("GET: %s", getRes) } ``` -------------------------------- ### Run Tile38 Server Source: https://github.com/tidwall/tile38/blob/master/README.md Starts the Tile38 server. Use the -h flag for command line options. ```bash ./tile38-server ``` -------------------------------- ### Basic Set and Get Operations with node-tile38 Source: https://github.com/tidwall/tile38/wiki/Node.js-example-(node-tile38) Demonstrates setting coordinates for objects and retrieving them as GeoJSON or simple points. Includes examples with and without explicit error handling. ```javascript const Tile38 = require('tile38'); const client = new Tile38(); // set a coordinate client.set('fleet', 'truck1', [33.5123, -112.2693]); ``` ```javascript // set a coordinate, with completion handler and error handler client.set('fleet', 'truck2', [33.5211, -112.2710]).then(() => { console.log("done"); }).catch(err => { console.error(err); }); ``` ```javascript // retrieve it as geojson object: client.get('fleet', 'truck1').then(obj => { // will print: { object: { type: 'Point', coordinates: [ -112.2693, 33.5123 ] } } console.dir(obj); }); ``` ```javascript // retrieve it as a simple point client.getPoint('fleet', 'truck2').then(obj => { // will print: { point: { lat: 33.5211, lon: -112.271 } } console.dir(obj); }); ``` ```javascript // same as above but adds error handling: client.getPoint('fleet', 'truck2').then(obj => { // will print: { point: { lat: 33.5211, lon: -112.271 } } console.dir(obj); }).catch(err => { console.error(err); }); ``` -------------------------------- ### Install Node Redis Source: https://github.com/tidwall/tile38/wiki/Node.js-example-(node-redis) Install the node-redis package using npm. This is the first step to using redis in your Node.js project. ```bash npm install redis ``` -------------------------------- ### Retrieve object using Python client Source: https://context7.com/tidwall/tile38/llms.txt Example of using the redis-py client to execute the GET command with WITHFIELDS and POINT options. ```python result = client.execute_command('GET', 'fleet', 'truck1', 'WITHFIELDS', 'POINT') ``` -------------------------------- ### Tile38 Commands with TinyRedisClient in PHP Source: https://github.com/tidwall/tile38/wiki/PHP-example-(tinyredisclient) Demonstrates initializing the TinyRedisClient and executing various Tile38 commands like SET, SCAN, NEARBY, GET, DEL, and DROP. ```php $redis = new \TinyRedisClient("127.0.0.1:9851"); $redis->__call("output", ["json"]); $redis->__call("set", ["fleet", "truck1", "point", 33.5123, -112.2693]); $redis->__call("set", ["fleet", "truck2", "point", 33.4626, -112.1695]); $redis->__call("scan", ["fleet"]); $redis->__call("nearby", ["fleet", "point", 33.462, -112.268, 6000]); $redis->__call("get", ["fleet", "truck1"]); $redis->__call("del", ["fleet", "truck2"]); $redis->__call("drop", ["fleet"]); ``` -------------------------------- ### Configuration Management Source: https://context7.com/tidwall/tile38/llms.txt Commands for getting, setting, and rewriting runtime configuration parameters. ```APIDOC ## CONFIG GET parameter ### Description Gets the value of a specific runtime configuration parameter. ### Method GET ### Endpoint /CONFIG ### Parameters #### Query Parameters - **parameter** (string) - Required - The name of the configuration parameter to retrieve (e.g., `requirepass`, `maxmemory`). ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. - **properties** (object) - An object containing the requested configuration parameter and its value. ### Response Example ```json { "ok": true, "properties": { "requirepass": "s3cret" } } ``` ``` ```APIDOC ## CONFIG SET parameter value ### Description Sets the value of a specific runtime configuration parameter. ### Method POST ### Endpoint /CONFIG ### Parameters #### Query Parameters - **parameter** (string) - Required - The name of the configuration parameter to set. - **value** (string) - Required - The new value for the configuration parameter. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. (Response body will contain confirmation) ``` ```APIDOC ## CONFIG REWRITE ### Description Persists the current in-memory configuration to the configuration file. ### Method POST ### Endpoint /CONFIG ### Parameters #### Query Parameters - **REWRITE** (string) - Required - Use the value `REWRITE` to trigger persistence. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. (Response body will contain confirmation) ``` -------------------------------- ### Get Tile38 configuration parameter Source: https://context7.com/tidwall/tile38/llms.txt Use CONFIG GET to retrieve the current value of a specific configuration parameter. This is useful for verifying settings. ```bash # Read the current password setting CONFIG GET requirepass # => {"ok":true,"properties":{"requirepass":"s3cret"}} ``` -------------------------------- ### Execute Tile38 Commands with Python Source: https://github.com/tidwall/tile38/wiki/Python-example Connect to a Tile38 instance and execute commands like SET and GET using the `execute_command` function. Ensure your Tile38 server is running on the specified host and port. ```python import redis def test_tile38(): client = redis.Redis(host='127.0.0.1', port=9851) # insert data result = client.execute_command('SET', 'fleet', 'truck', 'POINT', 33.32, 115.423) # print result print result # get data print client.execute_command('GET', 'fleet', 'truck') if __name__ == '__main__': test_tile38() ``` -------------------------------- ### Perform Basic SET and GET Operations Source: https://github.com/tidwall/tile38/blob/master/tests/README.md This snippet demonstrates a basic test operation involving setting a key with a POINT value and then retrieving it. It uses `DoBatch` to execute a sequence of Redis commands and their expected responses. ```go func keys_SET_test(mc *mockServer) error { return mc.DoBatch([][]interface{}{ {"SET", "fleet", "truck1", "POINT", 33.0001, -112.0001}, {"OK"}, {"GET", "fleet", "truck1", "POINT"}, {"[33.0001 -112.0001]"}, } } ``` -------------------------------- ### Store object using Go client Source: https://context7.com/tidwall/tile38/llms.txt Example of using the go-redis client to execute the SET command for storing a geographic object with fields. ```go import ( "context" "github.com/go-redis/redis/v8" ) ctx := context.Background() client := redis.NewClient(&redis.Options{Addr: "127.0.0.1:9851"}) cmd := redis.NewStringCmd(ctx, "SET", "fleet", "truck1", "FIELD", "speed", 72.5, "POINT", 33.5123, -112.2693) client.Process(ctx, cmd) // cmd.Result() => "OK", nil ``` -------------------------------- ### Install Redic Gem Source: https://github.com/tidwall/tile38/wiki/Ruby-example-(redic) Install the Redic gem using the RubyGems package manager. ```bash gem install redic ``` -------------------------------- ### Dispatching Tile38 Commands with Lettuce Source: https://github.com/tidwall/tile38/wiki/Java-example-(lettuce) Connect to a Tile38 instance using Lettuce and dispatch custom SET and GET commands. Requires Lettuce core and Redis client dependencies. ```java package example; import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; import io.lettuce.core.output.StatusOutput; import io.lettuce.core.protocol.CommandArgs; import io.lettuce.core.protocol.CommandType; public class Example { public static void main(String[] args) { RedisURI uri = RedisURI.Builder.redis("localhost", 9851).build(); RedisClient client = RedisClient.create(uri); StatefulRedisConnection connection = client.connect(); RedisCommands sync = connection.sync(); StringCodec codec = StringCodec.UTF8; sync.dispatch(CommandType.SET, new StatusOutput<>(codec), new CommandArgs<>(codec) .add("fleet") .add("truck1") .add("POINT") .add(33L) .add(-115L)); String result = sync.dispatch(CommandType.GET, new StatusOutput<>(codec), new CommandArgs<>(codec) .add("fleet") .add("truck1")); System.out.println(result); } } ``` -------------------------------- ### Retrieve a stored object with GET Source: https://context7.com/tidwall/tile38/llms.txt Use the GET command to retrieve an object by its key and ID. Specify output format (OBJECT, POINT, BOUNDS, HASH precision) and optionally include fields with WITHFIELDS. ```bash # Default (GeoJSON object) GET fleet truck1 # => {"ok":true,"object":{"type":"Point","coordinates":[-112.2693,33.5123]},"elapsed":"10µs"} ``` ```bash # Return as a point GET fleet truck1 POINT # => {"ok":true,"point":{"lat":33.5123,"lon":-112.2693},"elapsed":"8µs"} ``` ```bash # Return with all fields GET fleet truck1 WITHFIELDS POINT # => {"ok":true,"point":{"lat":33.5123,"lon":-112.2693},"fields":{"heading":270,"speed":72.5},"elapsed":"9µs"} ``` ```bash # Return as geohash with precision 7 GET fleet truck1 HASH 7 # => {"ok":true,"hash":"9tbnthx","elapsed":"6µs"} ``` ```bash # Via curl curl localhost:9851/GET+fleet+truck1+POINT # => {"ok":true,"point":{"lat":33.5123,"lon":-112.2693},"elapsed":"10µs"} ``` -------------------------------- ### Store object using Python client Source: https://context7.com/tidwall/tile38/llms.txt Example of using the redis-py client to execute the SET command for storing a geographic object with fields. ```python import redis client = redis.Redis(host='127.0.0.1', port=9851) client.execute_command('SET', 'fleet', 'truck1', 'FIELD', 'speed', 72.5, 'POINT', 33.5123, -112.2693) # => b'OK' ``` -------------------------------- ### Get Tile38 server statistics Source: https://context7.com/tidwall/tile38/llms.txt The SERVER command provides server-wide statistics, including version, memory allocation, and AOF size. The EXT option can provide extended statistics. ```bash # Server stats SERVER # => {"ok":true,"stats":{"id":"...","version":"1.36.x","num_collections":3,"num_objects":5,"mem_alloc":1234567,...},"elapsed":"50µs"} ``` -------------------------------- ### Store object using Node.js client Source: https://context7.com/tidwall/tile38/llms.txt Example of using the node-tile38 client to store a geographic point. ```javascript const Tile38 = require('tile38'); const client = new Tile38(); client.set('fleet', 'truck1', [33.5123, -112.2693]); ``` -------------------------------- ### Basic Redic Usage in Ruby Source: https://github.com/tidwall/tile38/wiki/Ruby-example-(redic) Connect to a Redis instance and execute SET and GET commands using the Redic gem. Ensure your Redis server is running on the specified host and port. ```ruby require 'redic' r = Redic.new 'redis://127.0.0.1:9851' r.call 'set', 'fleet', 'truck', 'point', '33', '-115' # => 'OK' r.call 'get', 'fleet', 'truck' # => '{"type":"Point","coordinates":[-115,33]}' ``` -------------------------------- ### Connect and Perform Redis Operations in Go Source: https://github.com/tidwall/tile38/wiki/Go-Example-(redigo) Connects to a Redis server and performs SET and GET operations. Ensure a Redis server is running on the specified port. ```go package main import ( "fmt" "log" "github.com/garyburd/redigo/redis" ) func main() { c, err := redis.Dial("tcp", ":9851") if err != nil { log.Fatalf("Could not connect: %v\n", err) } defer c.Close() ret, _ := c.Do("SET","fleet", "truck1", "POINT", "33", "-115") fmt.Printf("%s\n", ret) ret, _ = c.Do("GET","fleet", "truck1") fmt.Printf("%s\n", ret) } ``` -------------------------------- ### Get Object Source: https://github.com/tidwall/tile38/blob/master/README.md Retrieves the value associated with a specific key in a collection. Returns the object's data. ```tile38 get fleet truck1 ``` -------------------------------- ### HTTP Call with Set Command Source: https://github.com/tidwall/tile38/blob/master/README.md Example of calling a Tile38 command using HTTP with curl. The 'set' command is sent in the request body to the default Tile38 port. ```bash # call with request in the body curl --data "set fleet truck3 point 33.4762 -112.10923" localhost:9851 ``` -------------------------------- ### Send Tile38 Commands with Node Redis Source: https://github.com/tidwall/tile38/wiki/Node.js-example-(node-redis) Connect to a Tile38 instance and send custom commands like SET and GET using the `client.send_command` function. Handles potential errors and logs replies. ```javascript var redis = require("redis") var client = redis.createClient(9851, "localhost") client.send_command( "SET", ["fleet", "truck1", "POINT", "33", "-115"], function(err, reply){ if (err){ // ERROR }else{ console.log(reply) // OK } } ) client.send_command( "GET", ["fleet", "truck1"], function(err, reply){ if (err){ // ERROR }else{ console.log(reply) // {"type":"Point","coordinates":[-115,33]} } } ) ``` -------------------------------- ### Access Prometheus metrics endpoint Source: https://context7.com/tidwall/tile38/llms.txt Tile38 can expose Prometheus metrics via a dedicated endpoint. This requires starting the server with the `--metrics-addr` flag. ```bash # Prometheus metrics endpoint (requires --metrics-addr flag at startup) # ./tile38-server --metrics-addr=127.0.0.1:4321 curl http://127.0.0.1:4321/metrics ``` -------------------------------- ### Get statistics for Tile38 collections Source: https://context7.com/tidwall/tile38/llms.txt The STATS command returns per-collection statistics, including memory usage and object counts. Provide one or more collection names. ```bash # Stats for two collections STATS fleet zones # => {"ok":true,"stats":[{"in_memory_size":4096,"num_objects":2,"num_strings":0,"num_points":2,...},...],"elapsed":"300µs"} ``` -------------------------------- ### GET — Retrieve a stored object Source: https://context7.com/tidwall/tile38/llms.txt Retrieves an object by its collection key and ID. Supports various output formats and can include attached fields. ```APIDOC ## GET — Retrieve a stored object ### Description Retrieves an object by its collection key and ID. The optional output format modifier controls the return representation: `OBJECT` returns raw GeoJSON, `POINT` returns a lat/lon struct, `BOUNDS` returns a bounding box, and `HASH precision` returns a geohash of the specified length (1–12). `WITHFIELDS` includes attached numeric fields in the response. ### Method GET ### Parameters - **key** (string) - Required - The collection key. - **id** (string) - Required - The object ID. - **WITHFIELDS** - Optional - Includes attached numeric fields in the response. - **Output Format**: One of: - **OBJECT** - Returns raw GeoJSON. - **POINT** - Returns a lat/lon struct. - **BOUNDS** - Returns a bounding box. - **HASH** (precision) - Returns a geohash of the specified length (1–12). ### Request Example (CLI) ```bash GET fleet truck1 WITHFIELDS POINT ``` ### Request Example (HTTP) ```bash curl localhost:9851/GET+fleet+truck1+POINT ``` ### Response #### Success Response (200) - **ok** (boolean) - Indicates success. - **object** (object) - GeoJSON representation of the object (if OBJECT format is requested). - **point** (object) - Lat/lon struct (if POINT format is requested). - **lat** (number) - Latitude. - **lon** (number) - Longitude. - **bounds** (object) - Bounding box (if BOUNDS format is requested). - **hash** (string) - Geohash string (if HASH format is requested). - **fields** (object) - Attached numeric fields (if WITHFIELDS is used). - **elapsed** (string) - The time taken for the operation. ``` -------------------------------- ### Nearby Search with Cursor for Pagination Source: https://github.com/tidwall/tile38/blob/master/README.md Enables paginated retrieval of search results by using a cursor. Start with CURSOR 0 and continue with the returned cursor value until it becomes 0. ```tile38 CURSOR 0 ``` -------------------------------- ### Configure Tile38 server startup flags Source: https://context7.com/tidwall/tile38/llms.txt This snippet shows common server startup flags for Tile38, including port, data directory, config file, and persistence options. ```bash ./tile38-server \ -p 9851 \ -h 127.0.0.1 \ -d /var/lib/tile38 \ -f tile38.conf \ --metrics-addr 127.0.0.1:4321 \ --appendonly yes \ --appendfilename aof ``` -------------------------------- ### Configure Tile38 replication Source: https://context7.com/tidwall/tile38/llms.txt Use the FOLLOW command to instruct a Tile38 server to replicate from a leader. Specify the leader's host and port. Use 'FOLLOW NO' to stop replicating and promote to leader. ```bash # Start a follower that replicates from localhost:9851 ./tile38-server -p 9852 # In tile38-cli on port 9852: FOLLOW localhost 9851 # => {"ok":true,"elapsed":"500µs"} ``` ```bash # Stop following (become a standalone leader) FOLLOW NO ``` -------------------------------- ### Fetch Tile38 Keys and Initialize Viewer Source: https://github.com/tidwall/tile38/blob/master/internal/viewer/index.html Fetches all keys from Tile38 and dynamically creates links to load them as layers. Handles JSON parsing and error checking for the Tile38 response. ```javascript function t38fetch(url, cb) { var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { let resp = JSON.parse(this.responseText); if (!resp || !resp.ok) { throw resp.message; } else { cb(resp) } } }; req.open("GET", url, true); req.send(); } window.addEventListener("load", function() { t38fetch("/keys+\*", function(resp) { let list = document.getElementById("collist"); for (var i = 0; i < resp.keys.length; i++) { if (i > 0) { list.appendChild(document.createTextNode(" • ")); } let key = resp.keys[i] let link = document.createElement("A"); link.href = "#"; (function(link, key) { link.onclick = function() { loadlayer(key) } })(link, key); link.innerText = key list.appendChild(link); } }) }) ``` -------------------------------- ### Execute Tile38 commands via Telnet/TCP Source: https://context7.com/tidwall/tile38/llms.txt Shows how to interact with Tile38 using a raw TCP connection, such as with Telnet. Commands are sent directly, and responses are in RESP format. ```bash # Telnet / raw TCP telnet localhost 9851 SET fleet truck1 POINT 33.5123 -112.2693 +OK ``` -------------------------------- ### Interact with Tile38 using redis-rb Source: https://github.com/tidwall/tile38/wiki/Ruby-example-(redis-rb) Connect to a Tile38 server and use the `call` method to send commands. This is recommended because Tile38 uses Redis commands but not Redis semantics. ```ruby require 'redis' redis = Redis.new(host: 'localhost', port: 9851) redis.call(:set, 'fleet', 'truck1', 'POINT', '33', '-115') # => 'OK' redis.call(:get, 'fleet', 'truck1') # => '{"type":"Point","coordinates":[-115,33]}' ``` -------------------------------- ### Execute Tile38 commands via HTTP Source: https://context7.com/tidwall/tile38/llms.txt Demonstrates how to send Tile38 commands using HTTP, either in the request body or URL path. Spaces in the URL path should be replaced with '+'. ```bash # HTTP: command in request body curl --data "NEARBY fleet POINT 33.462 -112.268 6000" localhost:9851 # => {"ok":true,"objects":[...],"count":1,"cursor":0,"elapsed":"1ms"} # HTTP: command in URL path (spaces as +) curl "localhost:9851/NEARBY+fleet+POINT+33.462+-112.268+6000" ``` -------------------------------- ### Run Tile38 Tests Source: https://github.com/tidwall/tile38/blob/master/README.md Executes the test suite for the Tile38 project. ```bash make test ``` -------------------------------- ### Run Tile38 with Docker Source: https://github.com/tidwall/tile38/blob/master/README.md Pulls the latest stable version of Tile38 and runs it in a Docker container, exposing the default port. ```bash docker pull tile38/tile38 docker run -p 9851:9851 tile38/tile38 ``` -------------------------------- ### Get bounding box of a Tile38 collection Source: https://context7.com/tidwall/tile38/llms.txt The BOUNDS command returns the combined bounding box of all objects within a specified collection. This can help in spatial indexing and querying. ```bash # Bounding box of the fleet BOUNDS fleet # => {"ok":true,"bounds":{"type":"Point","coordinates":[-112.2693,33.5123]},"sw":{"lat":33.4626,"lon":-112.2695},"ne":{"lat":33.5123,"lon":-112.2693},"elapsed":"100µs"} ``` -------------------------------- ### List all collections in Tile38 Source: https://context7.com/tidwall/tile38/llms.txt Use the KEYS command to list all collection names matching a glob pattern. This is useful for understanding the current data structure. ```bash # List all collections KEYS * # => {"ok":true,"keys":["fleet","zones","sensors"],"elapsed":"200µs"} ``` -------------------------------- ### Set a point using Telnet Source: https://github.com/tidwall/tile38/blob/master/README.md Connect via Telnet to set a point. The server responds in RESP format by default. ```bash telnet localhost 9851 set fleet truck3 point 33.4762 -112.10923 +OK ``` -------------------------------- ### Authentication Source: https://context7.com/tidwall/tile38/llms.txt Command to authenticate with a password-protected Tile38 server. ```APIDOC ## AUTH password ### Description Authenticates the client with the server using the provided password. ### Method POST ### Endpoint /AUTH ### Parameters #### Query Parameters - **password** (string) - Required - The password for authentication. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the authentication was successful. (Response body will typically be `+OK` for RESP clients) ``` -------------------------------- ### Live geofence for intersection events Source: https://context7.com/tidwall/tile38/llms.txt Sets up a live geofence to detect specific events (e.g., 'cross') when objects intersect a bounding box. Events are streamed over WebSocket. ```bash INTERSECTS fleet FENCE DETECT cross BOUNDS 33.40 -112.35 33.55 -112.10 ``` -------------------------------- ### Access Tile38 CLI Source: https://github.com/tidwall/tile38/blob/master/README.md Connects to the Tile38 server running on localhost:9851 using the command line interface. ```bash ./tile38-cli ``` -------------------------------- ### Geofence Response - OK Source: https://github.com/tidwall/tile38/blob/master/README.md Server response indicating that a geofence has been successfully opened and is live. ```json {"ok":true,"live":true} ``` -------------------------------- ### Set Tile38 output format Source: https://context7.com/tidwall/tile38/llms.txt Use the OUTPUT command to force JSON or RESP output on a connection. This overrides the default format selection based on the client type. ```bash # Force JSON output on a RESP connection OUTPUT json # => +OK # Force RESP output OUTPUT resp ``` -------------------------------- ### Authenticate Tile38 connection Source: https://context7.com/tidwall/tile38/llms.txt Use the AUTH command to authenticate with a Tile38 server that requires a password. The password must be set using 'CONFIG SET requirepass'. ```bash # Authenticate on a password-protected server AUTH s3cret # => +OK ``` -------------------------------- ### Set Tile38 configuration parameters Source: https://context7.com/tidwall/tile38/llms.txt Use CONFIG SET to modify runtime configuration parameters like passwords or memory limits. These changes are applied immediately. ```bash # Require a password CONFIG SET requirepass "s3cret" # => {"ok":true} ``` ```bash # Limit memory to 512 MB CONFIG SET maxmemory 536870912 ``` ```bash # Automatic GC every 10 seconds CONFIG SET autogc 10 ``` -------------------------------- ### Create Pub/Sub Geofence Channel Source: https://context7.com/tidwall/tile38/llms.txt Creates a named channel for receiving geofence notifications over Tile38's pub/sub system. Clients subscribe to these channels. ```bash # Create a channel that fires when a bus is within 200m of a stop SETCHAN busstop NEARBY buses FENCE DETECT enter,exit POINT 33.5123 -112.2693 200 ``` -------------------------------- ### Create MQTT Webhook Geofence Source: https://context7.com/tidwall/tile38/llms.txt Registers a geofence that sends notifications to an MQTT broker. The endpoint URL can include query parameters like QoS. ```bash SETHOOK mqtthook "mqtt://broker:1883/fleet/alerts?qos=1" \ NEARBY fleet FENCE DETECT enter POINT 33.5 -112.2 500 ``` -------------------------------- ### Load and Execute Lua Script by SHA Source: https://context7.com/tidwall/tile38/llms.txt Pre-loads a Lua script into the server's cache and then executes it using its SHA1 hash. This is efficient for frequently used scripts. ```bash # Pre-load a script and call it by SHA SCRIPT LOAD "return tile38.call('GET', KEYS[1], ARGV[1], 'POINT')" # => {"ok":true,"sha1":"abc123...","elapsed":"50µs"} EVALSHA abc123 1 fleet truck1 ``` -------------------------------- ### Package Release Artifacts Source: https://github.com/tidwall/tile38/blob/master/scripts/RELEASE.md Build the release package for Tile38. This command generates the necessary artifacts, typically found in the 'packages' directory. ```bash make package ``` -------------------------------- ### Check Tile38 server role Source: https://context7.com/tidwall/tile38/llms.txt The ROLE command returns the current server role, which can be either 'leader' or 'follower'. For followers, it also shows the leader's address and replication position. ```bash # Check the role ROLE # => {"ok":true,"role":"follower","leader":{"addr":"localhost:9851","pos":12345}} ``` -------------------------------- ### Live geofence: stream events when trucks enter or exit the warehouse zone Source: https://context7.com/tidwall/tile38/llms.txt Sets up a live geofence to detect enter and exit events for objects within a specified bounding box. The server sends JSON messages for detected events. ```bash WITHIN fleet FENCE DETECT enter,exit BOUNDS 33.40 -112.35 33.55 -112.10 ``` -------------------------------- ### Subscribe to Tile38 Channels Source: https://context7.com/tidwall/tile38/llms.txt Allows clients to subscribe to specific geofence channels or patterns to receive real-time notifications. Supports glob-style pattern matching. ```bash # Subscribe to the channel from another connection SUBSCRIBE busstop # Server responds immediately: {"ok":true,"command":"subscribe","channel":"busstop","num":1} # Then streams events: {"command":"set","detect":"enter","id":"bus42","object":{...},"key":"buses"} # Pattern subscribe to all "zone.*" channels PSUBSCRIBE zone.* ``` -------------------------------- ### Replication Commands Source: https://context7.com/tidwall/tile38/llms.txt Commands for managing server replication, including following a leader and stopping replication. ```APIDOC ## FOLLOW host port ### Description Instructs this server to replicate from a leader server. ### Method POST ### Endpoint /FOLLOW ### Parameters #### Query Parameters - **host** (string) - Required - The hostname or IP address of the leader server. - **port** (integer) - Required - The TCP port of the leader server. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. - **elapsed** (string) - The time taken to execute the command. (Response body will contain confirmation) ``` ```APIDOC ## FOLLOW NO ### Description Stops the current server from following a leader, promoting it to a standalone leader. ### Method POST ### Endpoint /FOLLOW ### Parameters #### Query Parameters - **NO** (string) - Required - Use the value `NO` to stop following. ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. (Response body will contain confirmation) ``` ```APIDOC ## AOF pos ### Description Streams the append-only file from a specified byte position. Used internally by followers. ### Method GET ### Endpoint /AOF ### Parameters #### Query Parameters - **pos** (integer) - Required - The byte position to start streaming from. ### Response #### Success Response (200) (Response body will contain the AOF stream) ``` ```APIDOC ## AOFSHRINK ### Description Compacts the AOF file in the background. ### Method POST ### Endpoint /AOFSHRINK ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. (Response body will contain confirmation) ``` ```APIDOC ## ROLE ### Description Returns the current server role (`leader` or `follower`). ### Method GET ### Endpoint /ROLE ### Response #### Success Response (200) - **ok** (boolean) - Indicates if the command was successful. - **role** (string) - The current role of the server ('leader' or 'follower'). - **leader** (object) - Information about the leader if the role is 'follower'. ### Response Example ```json { "ok": true, "role": "follower", "leader": { "addr": "localhost:9851", "pos": 12345 } } ``` ``` -------------------------------- ### Create Kafka Webhook Geofence Source: https://context7.com/tidwall/tile38/llms.txt Registers a geofence that sends notifications to a Kafka topic. The endpoint specifies the Kafka broker and topic. ```bash SETHOOK kafkahook kafka://broker:9092/geofence-topic \ WITHIN fleet FENCE OBJECT '{"type":"Polygon",...}' ``` -------------------------------- ### Set Channel for Geofence Notifications Source: https://github.com/tidwall/tile38/blob/master/README.md Creates a static geofence that sends notifications to the 'busstop' pub/sub channel when a bus is within 200 meters of a specified point. ```bash > setchan busstop nearby buses fence point 33.5123 -112.2693 200 ``` -------------------------------- ### Execute Atomic Lua Script Source: https://context7.com/tidwall/tile38/llms.txt Executes a Lua script on the Tile38 server atomically. The script can call Tile38 commands using `tile38.call()` and access keys/arguments. ```bash # Atomic Lua script: set a point and return its TTL EVAL "tile38.call('SET', KEYS[1], ARGV[1], 'POINT', ARGV[2], ARGV[3]); return tile38.call('TTL', KEYS[1], ARGV[1])" 1 fleet truck99 33.5 -112.2 ``` -------------------------------- ### Paginate search results with cursor Source: https://context7.com/tidwall/tile38/llms.txt Fetches a subset of objects intersecting a bounding box using cursor-based pagination. Continue fetching subsequent pages by using the cursor value from the previous response. ```bash INTERSECTS fleet CURSOR 0 LIMIT 10 BOUNDS 33.40 -112.35 33.55 -112.10 ``` ```bash INTERSECTS fleet CURSOR 10 LIMIT 10 BOUNDS 33.40 -112.35 33.55 -112.10 ``` -------------------------------- ### Access Tile38 Prometheus Metrics Source: https://github.com/tidwall/tile38/blob/master/README.md Retrieves the Prometheus metrics from the Tile38 server. ```bash curl http://127.0.0.1:4321/metrics ``` -------------------------------- ### Nearby Fleet Fence with Detect Filter Source: https://github.com/tidwall/tile38/blob/master/README.md Establishes a geofence that monitors the 'fleet' collection and pre-filters responses to only include 'enter' and 'exit' detections within a 6 km radius. ```bash > nearby fleet fence detect enter,exit point 33.462 -112.268 6000 ``` -------------------------------- ### Tag New Release Source: https://github.com/tidwall/tile38/blob/master/scripts/RELEASE.md Create a Git tag for the new release using semantic versioning. This tag marks the specific point in history for the release. ```bash git tag $vers ``` -------------------------------- ### Manage Tile38 Hooks Source: https://context7.com/tidwall/tile38/llms.txt Commands to list, delete, and pattern-delete geofence hooks. Use '*' for all hooks or patterns for specific subsets. ```bash # List all hooks matching a pattern HOOKS * # Delete a specific hook DELHOOK myhook # Delete hooks matching a pattern PDELHOOK fleet* ``` -------------------------------- ### Push Tags to Remote Source: https://github.com/tidwall/tile38/blob/master/scripts/RELEASE.md Push all local tags, including the newly created release tag, to the remote repository. This makes the tag visible to others. ```bash git push --tags ``` -------------------------------- ### Initialize MapLibre Map and Controls Source: https://github.com/tidwall/tile38/blob/master/internal/viewer/index.html Initializes a MapLibre GL JS map with a public demo style and adds navigation and geolocate controls. The map container is set to 'map' and zoom is initialized to -1. ```javascript const map = new maplibregl.Map({ container: 'map', style: 'https://demotiles.maplibre.org/style.json', zoom: -1 }); // Controls (zoom/rotation + geolocate) map.addControl(new maplibregl.NavigationControl(), 'top-right'); map.addControl(new maplibregl.GeolocateControl({ positionOptions: { enableHighAccuracy: true }, trackUserLocation: true }), 'top-right'); ``` -------------------------------- ### Manage Tile38 Channels Source: https://context7.com/tidwall/tile38/llms.txt Commands to list, delete, and pattern-delete geofence channels. Use '*' for all channels or patterns for specific subsets. ```bash # List all channels CHANS * # Delete a channel DELCHAN busstop # Delete channels by pattern PDELCHAN bus* ``` -------------------------------- ### Subscribe to Pub/Sub Channel Source: https://github.com/tidwall/tile38/blob/master/README.md Subscribes to the 'busstop' channel to receive geofence notifications. ```bash > subscribe busstop ``` -------------------------------- ### Set Timeout for Tile38 Command Source: https://context7.com/tidwall/tile38/llms.txt Prepend any Tile38 command with a timeout value in seconds to limit its execution time. ```tile38 TIMEOUT 2.5 NEARBY fleet POINT 33.462 -112.268 6000 ``` -------------------------------- ### Create Redis Pub/Sub Webhook Geofence Source: https://context7.com/tidwall/tile38/llms.txt Registers a geofence that sends notifications to a Redis channel. The endpoint specifies the Redis server and channel. ```bash SETHOOK redishook redis://localhost:6379/geofence-channel \ NEARBY fleet FENCE POINT 33.5 -112.2 1000 ``` -------------------------------- ### Nearby Fleet Fence Point Command Source: https://github.com/tidwall/tile38/blob/master/README.md Opens a geofence that monitors the 'fleet' collection for objects within a 6 km radius around a specified point. The server keeps the connection open for real-time updates. ```bash > nearby fleet fence point 33.462 -112.268 6000 ``` -------------------------------- ### SETCHAN / SUBSCRIBE Source: https://context7.com/tidwall/tile38/llms.txt Creates a named Tile38 pub/sub geofence channel. Clients subscribe to receive push notifications without polling. Supports pattern subscriptions using `PSUBSCRIBE`. ```APIDOC ## SETCHAN / SUBSCRIBE — Pub/sub geofence channels `SETCHAN name [META name value ...] [EX seconds] NEARBY|WITHIN|INTERSECTS key FENCE [DETECT events] [COMMANDS cmds] ` `SUBSCRIBE channel [channel ...]` `PSUBSCRIBE pattern [pattern ...]` Creates a named Tile38 pub/sub geofence channel. Clients subscribe to receive push notifications without polling. Unlike webhooks, notifications are delivered over RESP connections. `PSUBSCRIBE` subscribes using glob patterns. ### Example ```bash # Create a channel that fires when a bus is within 200m of a stop SETCHAN busstop NEARBY buses FENCE DETECT enter,exit POINT 33.5123 -112.2693 200 # => {"ok":true,"elapsed":"800µs"} # Subscribe to the channel from another connection SUBSCRIBE busstop # Server responds immediately: {"ok":true,"command":"subscribe","channel":"busstop","num":1} # Then streams events: {"command":"set","detect":"enter","id":"bus42","object":{...},"key":"buses"} # Pattern subscribe to all "zone.*" channels PSUBSCRIBE zone.* ``` ## CHANS, DELCHAN, PDELCHAN List all channels: `CHANS *` Delete a channel: `DELCHAN busstop` Delete channels by pattern: `PDELCHAN bus*` ``` -------------------------------- ### Create HTTP Webhook Geofence Source: https://context7.com/tidwall/tile38/llms.txt Registers a geofence that sends HTTP POST notifications to a specified endpoint when objects enter or exit a defined area. Includes options for metadata and detection events. ```bash SETHOOK myhook http://myserver.com/geofence \ META source tile38 \ NEARBY fleet FENCE DETECT enter,exit POINT 33.5 -112.2 5000 ``` -------------------------------- ### Persist Tile38 configuration Source: https://context7.com/tidwall/tile38/llms.txt The CONFIG REWRITE command persists the current in-memory configuration to the configuration file, ensuring changes survive server restarts. ```bash # Persist the current configuration CONFIG REWRITE # => {"ok":true} ``` -------------------------------- ### Set a point using curl Source: https://github.com/tidwall/tile38/blob/master/README.md Use curl to set a point with a key and coordinates in the URL path. ```bash curl localhost:9851/set+fleet+truck3+point+33.4762+-112.10923 ``` -------------------------------- ### Load Tile38 Vector Tile Layer Source: https://github.com/tidwall/tile38/blob/master/internal/viewer/index.html Adds or removes a Tile38 vector tile layer to the map. It handles adding Mapbox Vector Tiles (MVT) as a source and styling points and polygons with different layers. Ensure the source-layer name 'tile38' matches your Tile38 data. ```javascript var sources = {} function loadlayer(key) { if (sources[key]) { map.removeLayer(key+'-fill-layer'); map.removeLayer(key+'-circle-layer'); map.removeSource(key+'-source'); } sources[key] = map.addSource(key+'-source', { type: 'vector', tiles: [ // Example MVT URL template (replace with your own endpoint) 'http://'+window.location.host+'/'+key+'/{z}/{x}/{y}.pbf' ], minzoom: 0, maxzoom: 23 }); // Add a layer using the vector tile source map.addLayer({ 'id': key+'-circle-layer', 'type': 'circle', 'source': key+'-source', 'source-layer': 'tile38', 'paint': { 'circle-radius': 5, 'circle-color': 'red', }, filter: ['==', ['get', 'type'], 'point'] }); // Add a layer using the vector tile source map.addLayer({ 'id': key+'-fill-layer', 'type': 'fill', 'source': key+'-source', 'source-layer': 'tile38', 'paint': { 'fill-color': '#00ff', 'fill-opacity': 0.5 }, filter: ['==', ['get', 'type'], 'polygon'] }); } ```