-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hello, World example in Go
- Loading branch information
Showing
6 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
Hello, World - DiceDB with Go | ||
=== | ||
|
||
This is a simple Hello, World application with DiceDB using Go SDK. | ||
The example, sets a key `k1` with value `v1` and then fetches | ||
the key `k1` to get the value `v1`. | ||
|
||
Before you run this example, please make sure you have installed | ||
DiceDB and are running it locally. | ||
|
||
> If not, you can change the connection parameters in the code | ||
> and make your code point to some remote running instance of | ||
> DiceDB | ||
To run the example, execute the following command from this directory | ||
|
||
```bash | ||
$ go run main.go | ||
``` |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module hello-world-go | ||
|
||
go 1.23.5 | ||
|
||
require github.com/dicedb/dicedb-go v1.0.2 | ||
|
||
require ( | ||
github.com/google/uuid v1.6.0 // indirect | ||
google.golang.org/protobuf v1.36.4 // indirect | ||
) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
github.com/dicedb/dicedb-go v1.0.2 h1:mq9DN7RlblKlhrdcSAFf1xqpVzAARsSPWHZ5REqilJ0= | ||
github.com/dicedb/dicedb-go v1.0.2/go.mod h1:pnhUYgUCPAtPycvuThbv3O6RXxVf5y8ZmDxQ8vyiXk0= | ||
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= | ||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= | ||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= | ||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= | ||
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM= | ||
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/dicedb/dicedb-go" | ||
"github.com/dicedb/dicedb-go/wire" | ||
) | ||
|
||
func main() { | ||
// create a new DiceDB client and connect to the server | ||
client, err := dicedb.NewClient("localhost", 7379) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer client.Close() | ||
|
||
// define a key and value | ||
key := "k1" | ||
value := "v1" | ||
|
||
// set the key and value | ||
resp := client.Fire(&wire.Command{ | ||
Cmd: "SET", | ||
Args: []string{key, value}, | ||
}) | ||
if resp.Err != "" { | ||
fmt.Println("error setting key:", resp.Err) | ||
return | ||
} | ||
fmt.Printf("successfully set key %s=%s\n", key, value) | ||
|
||
// get the key and value | ||
resp = client.Fire(&wire.Command{ | ||
Cmd: "GET", | ||
Args: []string{key}, | ||
}) | ||
if resp.Err != "" { | ||
fmt.Println("error getting key:", resp.Err) | ||
return | ||
} | ||
|
||
fmt.Printf("successfully got key %s=%s\n", key, resp.GetVStr()) | ||
} |