Created
July 21, 2025 09:35
-
-
Save alirezaarzehgar/e9bd31686017d88b93671aa2dbe2ac69 to your computer and use it in GitHub Desktop.
ScyllaDB Golang Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| version: "3.3" | |
| services: | |
| scylla1: | |
| container_name: scylla1 | |
| image: docker.arvancloud.ir/scylladb/scylla:latest | |
| ports: | |
| - 9001:9042 | |
| scylla2: | |
| container_name: scylla2 | |
| image: docker.arvancloud.ir/scylladb/scylla:latest | |
| ports: | |
| - 9002:9042 | |
| command: --seeds=scylla1 | |
| scylla3: | |
| container_name: scylla3 | |
| image: docker.arvancloud.ir/scylladb/scylla:latest | |
| ports: | |
| - 9003:9042 | |
| command: --seeds=scylla1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module scylla | |
| go 1.22.2 | |
| require ( | |
| github.com/gocql/gocql v1.7.0 | |
| github.com/scylladb/gocqlx v1.5.0 | |
| ) | |
| require ( | |
| github.com/golang/snappy v1.0.0 // indirect | |
| github.com/google/go-cmp v0.6.0 // indirect | |
| github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed // indirect | |
| gopkg.in/inf.v0 v0.9.1 // indirect | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "time" | |
| "github.com/gocql/gocql" | |
| ) | |
| func main() { | |
| cluster := gocql.NewCluster("localhost:9001", "localhost:9002", "localhost:9003") | |
| cluster.Consistency = gocql.Quorum | |
| session, _ := cluster.CreateSession() | |
| session.Query( | |
| `CREATE KEYSPACE IF NOT EXISTS test | |
| WITH REPLICATION = {'class': 'SimpleStrategy', 'replication_factor': '2'}`, | |
| ).Exec() | |
| session.Query(`CREATE TABLE IF NOT EXISTS test.users ( | |
| id UUID PRIMARY KEY, | |
| username text, | |
| email text | |
| )`).Exec() | |
| for range 100000 { | |
| uuid := fmt.Sprint(gocql.UUIDFromTime(time.Now())) | |
| q := `INSERT INTO test.users (id, username, email) VALUES (?, ?, ?)` | |
| session.Query(q, uuid, "username", "[email protected]").Exec() | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $!/usr/bin/env bash | |
| echo "fs.aio-max-nr = 4000000" >> /etc/sysctl.conf | |
| sysctl -p /etc/sysctl.conf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment