| 64 | } |
| 65 | |
| 66 | func (dm *EmbeddedDMap) setOrGetClusterClient() (Client, error) { |
| 67 | // Acquire the read lock and try to access the cluster client, if any. |
| 68 | dm.mtx.RLock() |
| 69 | if dm.clusterClient != nil { |
| 70 | dm.mtx.RUnlock() |
| 71 | return dm.clusterClient, nil |
| 72 | } |
| 73 | dm.mtx.RUnlock() |
| 74 | |
| 75 | // The cluster client is unset, try to create a new one. |
| 76 | dm.mtx.Lock() |
| 77 | defer dm.mtx.Unlock() |
| 78 | |
| 79 | // Check the existing value last time. There can be another running instances |
| 80 | // of this function. |
| 81 | if dm.clusterClient != nil { |
| 82 | return dm.clusterClient, nil |
| 83 | } |
| 84 | |
| 85 | // Create a new cluster client here. |
| 86 | c, err := NewClusterClient([]string{dm.client.db.rt.This().String()}) |
| 87 | if err != nil { |
| 88 | return nil, err |
| 89 | } |
| 90 | dm.clusterClient = c |
| 91 | |
| 92 | return dm.clusterClient, nil |
| 93 | } |
| 94 | |
| 95 | // Pipeline is a mechanism to realise Redis Pipeline technique. |
| 96 | // |