MCPcopy
hub / github.com/olric-data/olric / setOrGetClusterClient

Method setOrGetClusterClient

embedded_client.go:66–93  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

64}
65
66func (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//

Callers 2

PipelineMethod · 0.95
ScanMethod · 0.95

Calls 5

NewClusterClientFunction · 0.85
ThisMethod · 0.80
LockMethod · 0.65
UnlockMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected