Comments (4)
probably doesnt even compile.
func del_key(key string) (bool, error) {
redisUrl := "redis://localhost:6379"
p := &redis.Pool{
Dial: func() (redis.Conn, error) {
c, err := redis.DialURL(redisUrl)
return c, err
},
}
rs := redsync.New([]Pool{p})
m := rs.NewMutex("GLOBAL")
var err error
if err := m.Lock(); err != nil {
fmt.Println("Failed", err)
} else {
fmt.Println("Acquired")
defer m.Unlock()
}
c := p.Get()
defer c.Close()
return c.Do("DEL", "something")
}
from redsync.
@MaerF0x0 I suppose you mean the snippet above doesn't compile. I tried it out locally with Redsync and Redigo. Had to make two tiny changes to get it through the compiler:
func del_key(key string) (interface{}, error) {
redisUrl := "redis://localhost:6379"
p := &redis.Pool{
Dial: func() (redis.Conn, error) {
c, err := redis.DialURL(redisUrl)
return c, err
},
}
rs := redsync.New([]redsync.Pool{p})
m := rs.NewMutex("GLOBAL")
if err := m.Lock(); err != nil {
fmt.Println("Failed", err)
} else {
fmt.Println("Acquired")
defer m.Unlock()
}
c := p.Get()
defer c.Close()
return c.Do("DEL", "something")
}
from redsync.
Thanks for the sample. I am correct in assuming I can create one global Redsync var using redsync.New([]Pool{p}) or do I need a new one for each mutex?
I have done some tests using the global var using the race detector and it seems to run OK, but I am not sure because the pool is shared in NewMutex.
Also, if we have multiple Go instances (load balanced environment), will a single mutex be sufficient? I looks like you are using a local mutex inside the redsync mutex so on one instance it will work, but what if two or more Go instances will lock the same value? https://redis.io/topics/distlock talks about multiple Redis instances, but I am unsure how that translates to multiple Go instances.
Sorry if this is a novice question, but I think the docs could have some more info about the use cases and I am trying to "Make sure I understand how it works before using it in production environments." 😃
Thanks.
[edit]
After doing some more testing with multiple go instances it seems to work OK.
from redsync.
Hi @SebastiaanKlippert, thanks for trying it out. Glad to know it is working for you OK!
from redsync.
Related Issues (20)
- I having difficulty using mutex's custom HOT 1
- all the goroutines can not get the lock HOT 1
- cannot unlock when use static value HOT 3
- Need a way to execute arbitrary redis commands on a connection from a `Pool` HOT 3
- Wrong error text for unsuccessful Unlock() HOT 9
- go-redis v9 support HOT 1
- Need a way to execute arbitrary redis commands on a connection from a `Pool` HOT 2
- pool not exported by package goredis HOT 1
- Multi instance usage HOT 4
- Im need to use retry func for simulate native go mutex? HOT 3
- does NewMutex() return an existing mutex or does it always recreate? HOT 1
- 1 error occurred: * node #0: EOF HOT 1
- lock already taken, locked nodes: [0] HOT 2
- Can never unlock with redis v9 HOT 1
- The method Unlock throws error when there aren't any locks HOT 10
- why does using go to concurrently lock repeatedly succeed HOT 1
- Return after getting the quorum HOT 1
- when i try lock,and get lock,finally i extend the lock;but extend return error. HOT 7
- Redsync distributed lock has not been effective. HOT 3
- What should be used to write / read data to Redis when using redsync? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redsync.