Skip to content

Instantly share code, notes, and snippets.

@psahni
Last active July 27, 2024 12:27
Show Gist options
  • Save psahni/02ce47cb3340ea1438efc6c49b6d4da6 to your computer and use it in GitHub Desktop.
Save psahni/02ce47cb3340ea1438efc6c49b6d4da6 to your computer and use it in GitHub Desktop.
code_snippets_go.go
type Employee string

const (
	Manager      Employee = "manager"
	Developer    Employee = "Developer"
	Tester       Employee = "Tester"
)
@psahni
Copy link
Author

psahni commented Nov 21, 2023

@psahni
Copy link
Author

psahni commented Jul 27, 2024

Save Hash

Get Hash Key

func main() {
	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})

	err := client.HMSet("hashkey", map[string]interface{}{
		"field1": "value1",
		"field2": "value2",
	}).Err()
	if err != nil {
		panic(err)
	}

	vals, err := client.HMGet("hashkey", "field1", "field2").Result()
	if err != nil {
		panic(err)
	}

	for _, v := range vals {
		fmt.Println(v)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment