Author: Thirty-three days

Blog: www.zhouhuibo.club

Through the process of learning and sharing, I will summarize the problems and technologies in my work and output them. I hope that both the novice and the veteran can gain new knowledge through their own articles and put it into practice.

The introduction

The map type native to the Go language does not support concurrent reads and writes.

Prior to Go 1.9, concurrent maps were not implemented in the Go language standard library. In Go 1.9, sync.map was introduced.

Concurrent – the advantage of the map

Concurrent-map provides a high-performance solution to reduce lock granularity by sharding internal maps to minimize lock wait times (lock conflicts).

Sync.map differs from this concurrent-map in several key ways.

Sync.map in the standard library is designed for append-only scenarios. Therefore, if you want to use Map for a similar in-memory database, you might benefit from using our version.

You can read more on Golang repo, here and here sync.map is better for read and write, otherwise concurrency is poor.

usage

go get "github.com/orcaman/concurrent-map"
Copy the code
import (
	"github.com/orcaman/concurrent-map"
)
Copy the code

The sample

Not too different from the original writing, right

// create a New map.m := map.new () // set variable m with a key of "foo" and a value of "bar" key pair m.et ("foo", "bar") // get the specified key value from m. ok := m.Get("foo"); Ok {bar := TMP.(string)} // Delete key "foo" item m.emove ("foo")Copy the code

Resource list

Github.com/orcaman/con…

END

Welcome to pay attention to the public number programmer tool set 👍👍 is committed to sharing excellent open source projects, learning resources, common tools

Reply keyword “attention package”, send you a complete map of programmer skills.

Reply keyword “wX” add personal wechat, hook up with the author, welcome to chat ^-^.