Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added redis shorthand command #413

Merged
merged 9 commits into from
Aug 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Added Elastic HQ support available at elastichq.mydomain.test for viewing Elasticsearch data ([#350](https://github.com/davidalger/warden/pull/350) by @Den4ik)
* Update selenium to standalone latest version resolving issues with old hub/chrome image combinations ([#349](https://github.com/davidalger/warden/pull/349) by @Den4ik)
* Environment and image build improvements ([#363](https://github.com/davidalger/warden/pull/363) by @Den4ik)
* Introduces new redis sub-command for easy access to the running redis container ([#413](https://github.com/davidalger/warden/pull/413) by @werfu)

**Bug Fixes:**

Expand Down
2 changes: 1 addition & 1 deletion bin/warden
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare WARDEN_PARAMS=()
declare WARDEN_CMD_VERB=
declare WARDEN_CMD_EXEC=
declare WARDEN_CMD_HELP=
declare WARDEN_CMD_ANYARGS=(svc env db sync shell debug)
declare WARDEN_CMD_ANYARGS=(svc env db redis sync shell debug)

## parse first argument as command and determine validity
if (( "$#" )); then
Expand Down
22 changes: 22 additions & 0 deletions commands/redis.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

WARDEN_ENV_PATH="$(locateEnvPath)" || exit $?
loadEnvConfig "${WARDEN_ENV_PATH}" || exit $?
assertDockerRunning

if [[ ${WARDEN_REDIS:-1} -eq 0 ]]; then
fatal "Redis environment is not used (WARDEN_REDIS=0)."
fi

if [[ "${WARDEN_PARAMS[0]}" == "help" ]]; then
warden redis --help || exit $? && exit $?
fi

## load connection information for the redis service
REDIS_CONTAINER=$(warden env ps -q redis)
if [[ ! ${REDIS_CONTAINER} ]]; then
fatal "No container found for redis service."
fi

"${WARDEN_DIR}/bin/warden" env exec redis redis-cli "${WARDEN_PARAMS[@]}" "$@"
12 changes: 12 additions & 0 deletions commands/redis.help
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
[[ ! ${WARDEN_DIR} ]] && >&2 echo -e "\033[31mThis script is not intended to be run directly!\033[0m" && exit 1

WARDEN_USAGE=$(cat <<EOF
\033[33mUsage:\033[0m
redis Launches an interactive redis session within the current project environment
redis COMMAND Execute any valid Redis command within the current project environment

\033[33mOptions:\033[0m
-h, --help Display this help menu
EOF
)
1 change: 1 addition & 0 deletions commands/usage.help
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Warden version $(cat ${WARDEN_DIR}/version)
env-init Configure environment by adding '.env' file to the current working directory
env Controls an environment from any point within the root project directory
db Interacts with the db service on an environment (see 'warden db -h' for details)
redis Interacts with the redis service on an environment (see 'warden redis -h' for details)
install Initializes or updates warden configuration on host machine
shell Launches into a shell within the current project environment
debug Launches debug enabled shell within current project environment
Expand Down
8 changes: 6 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ Flush varnish:

Connect to redis:

warden env exec redis redis-cli
warden redis

Flush redis completely:

warden env exec -T redis redis-cli flushall
warden redis flushall

Run redis continous stat mode

warden redis --stat

Remove volumes completely:

Expand Down