Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
phpredis/tests/make-cluster.sh at develop · SmallEasy/phpredis · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
SmallEasy
/
phpredis
Public
forked from
phpredis/phpredis
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
develop
Breadcrumbs
phpredis
/
tests
/
make-cluster.sh
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
executable file
·
142 lines (118 loc) · 3.22 KB
develop
Breadcrumbs
phpredis
/
tests
/
make-cluster.sh
Copy path
Top
File metadata and controls
Code
Blame
executable file
·
142 lines (118 loc) · 3.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!
/bin/bash
#
make-cluster.sh
#
This is a simple script used to automatically spin up a Redis cluster instance
#
simplifying the process of running unit tests.
#
#
Usage:
#
./make-cluster.sh start [host]
#
./make-cluster.sh stop [host]
#
BASEDIR=
`
pwd
`
NODEDIR=
$BASEDIR
/nodes
MAPFILE=
$NODEDIR
/nodemap
#
Host, nodes, replicas, ports, etc. Change if you want different values
HOST=
"
127.0.0.1
"
NODES=12
REPLICAS=3
START_PORT=7000
END_PORT=
`
expr
$START_PORT
+
$NODES
`
#
Helper to determine if we have an executable
checkExe
() {
if
!
hash
$1
>
/dev/null
2>&1
;
then
echo
"
Error: Must have
$1
on the path!
"
exit
1
fi
}
#
Run a command and output what we're running
verboseRun
() {
echo
"
Running:
$@
"
$@
}
#
Spawn a specific redis instance, cluster enabled
spawnNode
() {
#
Attempt to spawn the node
verboseRun redis-server --cluster-enabled yes --dir
$NODEDIR
--port
$PORT
\
--cluster-config-file node-
$PORT
.conf --daemonize yes --save
\'\'
\
--bind
$HOST
--dbfilename node-
$PORT
.rdb
#
Abort if we can't spin this instance
if
[
$?
-ne
0 ]
;
then
echo
"
Error: Can't spawn node at port
$PORT
.
"
exit
1
fi
}
#
Spawn nodes from start to end port
spawnNodes
() {
for
PORT
in
`
seq
$START_PORT
$END_PORT
`
;
do
#
Attempt to spawn the node
spawnNode
$PORT
#
Add this host:port to our nodemap so the tests can get seeds
echo
"
$HOST
:
$PORT
"
>>
$MAPFILE
done
}
#
Check to see if any nodes are running
checkNodes
() {
echo
-n
"
Checking port availability
"
for
PORT
in
`
seq
$START_PORT
$END_PORT
`
;
do
redis-cli -p
$PORT
ping
>
/dev/null
2>&1
if
[
$?
-eq
0 ]
;
then
echo
"
FAIL
"
echo
"
Error: There appears to be an instance running at port
$PORT
"
exit
1
fi
done
echo
"
OK
"
}
#
Create our 'node' directory if it doesn't exist and clean out any previous
#
configuration files from a previous run.
cleanConfigInfo
() {
verboseRun mkdir -p
$NODEDIR
verboseRun rm -f
$NODEDIR
/
*
}
#
Initialize our cluster with redis-trib.rb
initCluster
() {
TRIBARGS=
"
"
for
PORT
in
`
seq
$START_PORT
$END_PORT
`
;
do
TRIBARGS=
"
$TRIBARGS
$HOST
:
$PORT
"
done
verboseRun redis-trib.rb create --replicas
$REPLICAS
$TRIBARGS
if
[
$?
-ne
0 ]
;
then
echo
"
Error: Couldn't create cluster!
"
exit
1
fi
}
#
Attempt to spin up our cluster
startCluster
() {
#
Make sure none of these nodes are already running
checkNodes
#
Clean out node configuration, etc
cleanConfigInfo
#
Attempt to spawn the nodes
spawnNodes
#
Attempt to initialize the cluster
initCluster
}
#
Shut down nodes in our cluster
stopCluster
() {
for
PORT
in
`
seq
$START_PORT
$END_PORT
`
;
do
verboseRun redis-cli -p
$PORT
SHUTDOWN NOSAVE
>
/dev/null
2>&1
done
}
#
Make sure we have redis-server and redis-trib.rb on the path
checkExe redis-server
checkExe redis-trib.rb
#
Override the host if we've got $2
if
[[
!
-z
"
$2
"
]]
;
then
HOST=
$2
fi
#
Main entry point to start or stop/kill a cluster
case
"
$1
"
in
start)
startCluster
;;
stop)
stopCluster
;;
*
)
echo
"
Usage
$0
<start|stop> [host]
"
;;
esac
You can’t perform that action at this time.