├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── release.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── COPYING ├── Makefile ├── README.md ├── debian ├── README ├── README.Debian ├── README.source ├── changelog ├── compat ├── control ├── copyright ├── docs ├── redis-bash.docs └── rules ├── redis-bash-cli ├── redis-bash-lib └── redis-pubsub-test /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Run the command '....' 16 | 2. See error 17 | 18 | **Expected behavior** 19 | A clear and concise description of what you expected to happen. 20 | 21 | **Screenshots** 22 | If applicable, add screenshots to help explain your problem. 23 | 24 | **Details (please complete the following information):** 25 | - OS: [e.g. Linux] 26 | - Version [e.g. Ubuntu 22.04] 27 | - Redis server version 28 | 29 | **Additional context** 30 | Add any other context about the problem here. 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*.*.*' 7 | 8 | env: 9 | CHANGELOG_AUTHOR_NAME: "github-actions[bot]" 10 | CHANGELOG_AUTHOR_EMAIL: "41898282+github-actions[bot]@users.noreply.github.com" 11 | 12 | jobs: 13 | build-debian-package: 14 | runs-on: ubuntu-latest 15 | 16 | steps: 17 | - name: Retrieve app token 18 | id: app 19 | uses: Flutter-Tech/github-app-token@v2 20 | with: 21 | APP_PEM: ${{ secrets.APPLICATION_PRIVATE_KEY }} 22 | APP_ID: ${{ secrets.APPLICATION_ID }} 23 | APP_INSTALLATION_ID: ${{ secrets.APPLICATION_INSTALL_ID }} 24 | 25 | - name: Checkout code 26 | uses: actions/checkout@v3 27 | with: 28 | fetch-depth: 0 29 | token: ${{ steps.app.outputs.app_token }} 30 | ref: ${{ github.ref_name }} 31 | 32 | - name: Patch changelog (snapshot) 33 | uses: pi-top/git-debian-changelog-bump-action@master 34 | with: 35 | release: true 36 | author_name: ${{ env.CHANGELOG_AUTHOR_NAME }} 37 | author_email: ${{ env.CHANGELOG_AUTHOR_EMAIL }} 38 | 39 | - name: Apply git-debian-changelog-bump-action changes 40 | run: | 41 | if [ ! -z "$(git status --porcelain=v1 2>/dev/null)" ] 42 | then 43 | git switch master 44 | git config --global user.email "${{ env.CHANGELOG_AUTHOR_EMAIL }}" 45 | git config --global user.name "${{ env.CHANGELOG_AUTHOR_NAME }}" 46 | git pull --no-edit 47 | git add -A 48 | git commit -m "git-debian-changelog-bump-action changes" 49 | git push 50 | fi 51 | 52 | - name: Determine current version 53 | run: | 54 | sudo apt install -y dpkg-dev 55 | echo "CURRENT_VERSION=$(dpkg-parsechangelog -Sversion)" >> $GITHUB_ENV 56 | 57 | - uses: jtdor/build-deb-action@v1 58 | env: 59 | DEB_BUILD_OPTIONS: noautodbgsym 60 | with: 61 | buildpackage-opts: --build=binary --no-sign 62 | 63 | - uses: actions/upload-artifact@v2 64 | with: 65 | name: redis-bash_${{ env.CURRENT_VERSION }}_all.deb 66 | path: debian/artifacts/redis-bash_${{ env.CURRENT_VERSION }}_all.deb 67 | 68 | - name: Create a GitHub release 69 | uses: softprops/action-gh-release@v1 70 | with: 71 | files: debian/artifacts/redis-bash_${{ env.CURRENT_VERSION }}_all.deb 72 | token: ${{ secrets.GITHUB_TOKEN }} 73 | generate_release_notes: true 74 | 75 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | debian/files 2 | debian/redis-bash.debhelper.log 3 | debian/redis-bash.substvars 4 | debian/redis-bash/ 5 | debian/source/ 6 | debian/artifacts/ 7 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to make participation in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community include: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct which could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces, and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | cassianoaquino at me.com. 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | https://www.contributor-covenant.org/faq. Translations are available at 128 | https://www.contributor-covenant.org/translations. 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | To submit any contribution to this repository please fork this repository and submit a pull request. 2 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, Cassiano Aquino 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 11 | 2. Redistributions in binary form must reproduce the above copyright notice, 12 | this list of conditions and the following disclaimer in the documentation 13 | and/or other materials provided with the distribution. 14 | 15 | 3. Neither the name of the copyright holder nor the names of its 16 | contributors may be used to endorse or promote products derived from 17 | this software without specific prior written permission. 18 | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 23 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 25 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 26 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 27 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | clean: 2 | 3 | install: 4 | install -d $(DESTDIR)/usr/share/redis-bash/ 5 | install -d $(DESTDIR)/usr/bin 6 | install -v -m 755 redis-bash-cli $(DESTDIR)/usr/bin/ 7 | install -v -m 644 redis-bash-lib $(DESTDIR)/usr/share/redis-bash/ 8 | install -v -m 755 redis-pubsub-test ${DESTDIR}/usr/share/redis-bash/ 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # REDIS-BASH - Bash library to access Redis Databases 2 | 3 | [![Release](https://github.com/caquino/redis-bash/actions/workflows/release.yml/badge.svg)](https://github.com/caquino/redis-bash/actions/workflows/release.yml) 4 | * The library comes with two examples, one generic client and a pubsub demo. 5 | * This library has no external dependencies, using only bash built-in commands. 6 | * The only requirement is bash to have net redirections enabled. 7 | * The command validation is made by the server. 8 | 9 | ## Using the client and the pubsub demo 10 | 11 | ### Client 12 | ```bash 13 | $ redis-bash-cli 14 | ``` 15 | 16 | Parameters: 17 | 18 | ``` 19 | -h Host - Defaults localhost. 20 | -p Port - Defaults 6379. 21 | -n DB - Select the database DB. 22 | -r N - Repeat command N times. 23 | -a PASSWORD - Authentication password 24 | -i INTERVAL - Interval between commands 25 | ``` 26 | 27 | Examples: 28 | 29 | ```bash 30 | $ redis-bash-cli -h localhost SET testkey 1234 31 | OK 32 | 33 | $ redis-bash-cli -h localhost GET testkey 34 | 1234 35 | 36 | $ redis-bash-cli -h localhost PING 37 | PONG 38 | 39 | $ redis-bash-cli -h localhost -r 5 PING 40 | PONG 41 | PONG 42 | PONG 43 | PONG 44 | PONG 45 | 46 | $ redis-bash-cli -h localhost WRONGCOMMAND test 47 | ERR unknown command 'WRONGCOMMAND' 48 | ``` 49 | 50 | Authenticated requests: 51 | 52 | ```bash 53 | $ redis-bash-cli -h localhost PING 54 | ERR operation not permitted 55 | 56 | $ redis-bash-cli -h localhost -a test PING 57 | PONG 58 | ``` 59 | 60 | ### Pubsub 61 | 62 | ```bash 63 | $ redis-pubsub-test 64 | ``` 65 | 66 | Parameters: 67 | 68 | ```bash 69 | -h Host - Defaults localhost. 70 | -p Port - Defaults 6379. 71 | CHANNEL - Channel to subscribe 72 | ``` 73 | 74 | ## Pubsub demo 75 | In one shell run the command: 76 | 77 | ```bash 78 | $ redis-pubsub-test test 79 | ``` 80 | 81 | In another shell run the command: 82 | 83 | ```bash 84 | $ redis-bash-cli -h localhost -p 6379 PUBLISH test "Hello World." 85 | ``` 86 | 87 | # Using the Library in your code 88 | The library have a single function to handle the redis communication. 89 | 90 | ```bash 91 | $ redis-client 92 | ``` 93 | 94 | * FD: file descriptor to access the redis database 95 | * COMMAND: command to be sent to the server, can be blank to do read operation. 96 | 97 | Using the library: 98 | 99 | ```bash 100 | #!/bin/bash 101 | source redis-bash-lib # include the library 102 | exec 6<>/dev/tcp/localhost/6379 # open the connection 103 | redis-client 6 SET test 1234 # do a SET operation 104 | exec 6>&- # close the connection 105 | ``` 106 | 107 | # TODO 108 | * manual page 109 | * tests 110 | * documentation 111 | 112 | # LICENSE 113 | * BSD 114 | 115 | # Debian Package 116 | * To build the debian/ubuntu package use dpkg-buildpackage. 117 | 118 | # CONTACT 119 | * email: cassianoaquino at me.com 120 | * twitter: @syshero 121 | * blog: http://syshero.org/ 122 | 123 | # THANKS 124 | * Andre Ferraz - Debian Package 125 | * Juliano Martinez - Idea to handle socket disconnections on the pubsub demo 126 | 127 | # TESTED 128 | * Debian squeeze 6.0.X - GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu) 129 | * Mac OS X Lion 10.7.X - GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11) 130 | 131 | # PERFORMANCE 132 | 133 | This test has no intent to be a complete benchmark, but only to show the diference between both clients. 134 | 135 | 136 | ```bash 137 | $ time redis-bash-cli -h 192.168.86.1 -r 10 PING > /dev/null 138 | 139 | real0m0.027s 140 | user0m0.000s 141 | sys0m0.024s 142 | 143 | $ time redis-cli -h 192.168.86.1 -r 10 PING > /dev/null 144 | 145 | real0m0.012s 146 | user0m0.000s 147 | sys0m0.008s 148 | ``` 149 | -------------------------------------------------------------------------------- /debian/README: -------------------------------------------------------------------------------- 1 | The Debian Package redis-bash 2 | ---------------------------- 3 | 4 | Comments regarding the Package 5 | 6 | -- Andre Ferraz Fri, 28 Oct 2011 19:45:24 +0000 7 | -------------------------------------------------------------------------------- /debian/README.Debian: -------------------------------------------------------------------------------- 1 | redis-bash for Debian 2 | --------------------- 3 | 4 | 5 | 6 | -- Andre Ferraz Fri, 28 Oct 2011 19:45:24 +0000 7 | -------------------------------------------------------------------------------- /debian/README.source: -------------------------------------------------------------------------------- 1 | redis-bash for Debian 2 | --------------------- 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /debian/changelog: -------------------------------------------------------------------------------- 1 | redis-bash (1.0.1) unstable; urgency=medium 2 | 3 | * Catch "no reply" error. 4 | * fix license. 5 | * Support Bash v5 and drop support for bash version < 3 6 | * Create LICENSE 7 | * add github actions workflow 8 | * change artifact name 9 | * change workflow 10 | * copy redis-pubsub-test to dest on install 11 | * commit back changelog changes 12 | * workflow changes 13 | * workflow changes 14 | * bump checkout action 15 | * change workflow 16 | * add app to workflow 17 | * change app flow 18 | * fix 19 | * remove action 20 | * add checkout 21 | * changes 22 | * add master 23 | * add depth to checkout 24 | 25 | -- github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Wed, 28 Dec 2022 13:03:45 +0000 26 | 27 | redis-bash (1.0.0) unstable; urgency=low 28 | 29 | * Initial Release. 30 | 31 | -- Andre Ferraz Fri, 28 Oct 2011 19:45:24 +0000 32 | -------------------------------------------------------------------------------- /debian/compat: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /debian/control: -------------------------------------------------------------------------------- 1 | Source: redis-bash 2 | Section: shells 3 | Priority: extra 4 | Maintainer: Andre Ferraz 5 | Build-Depends: debhelper (>= 7.0.50~) 6 | Standards-Version: 3.8.4 7 | Homepage: https://github.com/caquino/redis-bash 8 | #Vcs-Git: git://git.debian.org/collab-maint/redis-bash.git 9 | #Vcs-Browser: http://git.debian.org/?p=collab-maint/redis-bash.git;a=summary 10 | 11 | Package: redis-bash 12 | Architecture: all 13 | Depends: ${shlibs:Depends}, ${misc:Depends}, bash 14 | Description: Redis protocol implementation written in bash 15 | Redis protocol implementation written in bash 16 | -------------------------------------------------------------------------------- /debian/copyright: -------------------------------------------------------------------------------- 1 | This work was packaged for Debian by: 2 | 3 | Andre Ferraz on Fri, 28 Oct 2011 19:45:24 +0000 4 | 5 | It was downloaded from: 6 | 7 | 8 | 9 | Upstream Author(s): 10 | 11 | 12 | 13 | 14 | Copyright: 15 | 16 | 17 | 18 | 19 | License: 20 | 21 | This program is free software: you can redistribute it and/or modify 22 | it under the terms of the GNU General Public License as published by 23 | the Free Software Foundation, either version 3 of the License, or 24 | (at your option) any later version. 25 | 26 | This package is distributed in the hope that it will be useful, 27 | but WITHOUT ANY WARRANTY; without even the implied warranty of 28 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 29 | GNU General Public License for more details. 30 | 31 | You should have received a copy of the GNU General Public License 32 | along with this program. If not, see . 33 | 34 | On Debian systems, the complete text of the GNU General 35 | Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". 36 | 37 | The Debian packaging is: 38 | 39 | Copyright (C) 2011 Andre Ferraz 40 | 41 | # Please chose a license for your packaging work. If the program you package 42 | # uses a mainstream license, using the same license is the safest choice. 43 | # Please avoid to pick license terms that are more restrictive than the 44 | # packaged work, as it may make Debian's contributions unacceptable upstream. 45 | # If you just want it to be GPL version 3, leave the following line in. 46 | 47 | and is licensed under the GPL version 3, see above. 48 | 49 | # Please also look if there are files or directories which have a 50 | # different copyright/license attached and list them here. 51 | -------------------------------------------------------------------------------- /debian/docs: -------------------------------------------------------------------------------- 1 | README.md 2 | -------------------------------------------------------------------------------- /debian/redis-bash.docs: -------------------------------------------------------------------------------- 1 | README.md 2 | redis-pubsub-test 3 | -------------------------------------------------------------------------------- /debian/rules: -------------------------------------------------------------------------------- 1 | #!/usr/bin/make -f 2 | # -*- makefile -*- 3 | # Sample debian/rules that uses debhelper. 4 | # This file was originally written by Joey Hess and Craig Small. 5 | # As a special exception, when this file is copied by dh-make into a 6 | # dh-make output file, you may use that output file without restriction. 7 | # This special exception was added by Craig Small in version 0.37 of dh-make. 8 | 9 | # Uncomment this to turn on verbose mode. 10 | #export DH_VERBOSE=1 11 | 12 | %: 13 | dh $@ 14 | -------------------------------------------------------------------------------- /redis-bash-cli: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # https://github.com/caquino/redis-bash 3 | # Poor man profiling - uncoment the next 2 lines 4 | #set -x 5 | #PS4='$(date "+%s.%N ($LINENO) + ")' 6 | source /usr/share/redis-bash/redis-bash-lib 2> /dev/null 7 | if [ $? -ne 0 ]; then 8 | LIBFOLDER=${0%/${0##*/}} 9 | source ${LIBFOLDER}/redis-bash-lib 2> /dev/null 10 | if [ $? -ne 0 ]; then 11 | echo "can't find redis-bash-lib in /usr/share/redis-bash or ${LIBFOLDER}" 12 | exit 127 13 | fi 14 | fi 15 | REDISHOST=localhost 16 | REDISPORT=6379 17 | REPEAT=1 18 | DELAY=0 19 | while getopts ":h:n:p:r:a:i:" opt 20 | do 21 | case ${opt} in 22 | h) REDISHOST=${OPTARG};; 23 | n) REDISDB=${OPTARG};; 24 | p) REDISPORT=${OPTARG};; 25 | r) REPEAT=${OPTARG};; 26 | a) AUTH=${OPTARG};; 27 | i) DELAY=${OPTARG};; 28 | esac 29 | done 30 | shift $((${OPTIND} - 1)) 31 | if [ "${REDISHOST}" != "" ] && [ "${REDISPORT}" != "" ] 32 | then 33 | # open fd 34 | exec 6<>/dev/tcp/"$REDISHOST"/"$REDISPORT" || exit 35 | else 36 | echo "Wrong arguments" 37 | exit 255 38 | fi 39 | [ "${AUTH}" != "" ] && redis-client 6 AUTH "$AUTH" > /dev/null 40 | [ "${REDISDB}" != "" ] && redis-client 6 SELECT "$REDISDB" > /dev/null 41 | for ((z=1;z<=${REPEAT};z++)) 42 | do 43 | redis-client 6 "$@" || exit 44 | [ ${DELAY} -gt 0 ] && sleep ${DELAY} 45 | done 46 | exec 6>&- #close fd 47 | -------------------------------------------------------------------------------- /redis-bash-lib: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # https://github.com/caquino/redis-bash 3 | 4 | # -- redis-client 5 | # 6 | # returns an array 7 | # 8 | # Args: 9 | # value -- file descriptor 10 | # value -- message to be sent (only read if blank) 11 | # 12 | 13 | if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then 14 | echo "This script requires bash version 4+" 15 | exit 1 16 | fi 17 | 18 | function redis-client() { 19 | if [ ${#FUNCNAME[@]} -lt 100 ]; then 20 | FD=${1} 21 | shift; 22 | if [ ${#} -ne 0 ]; then # always use unified protocol and let the server validate the number of parameters 23 | local ARRAY=( "${@}" ) 24 | local CMD=("*$[${#ARRAY[@]}]") 25 | local i=0 26 | for ((i=0;i<${#ARRAY[@]};i++)); do 27 | CMD=( "${CMD[@]}" "\$${#ARRAY[${i}]}" "${ARRAY[${i}]}" ) 28 | done 29 | printf "%s\r\n" "${CMD[@]}" >&${FD} 30 | fi 31 | local ARGV 32 | read -r -u ${FD} 33 | 34 | if [ ${#REPLY} -eq 0 ]; then 35 | printf "error: no reply\n" 36 | exit 1 37 | fi 38 | 39 | REPLY=${REPLY:0:${#REPLY}-1} 40 | case ${REPLY} in 41 | -*|\$-*) # error message 42 | echo "${REPLY:1}" 43 | return 1;; 44 | \$*) # message size 45 | [ ${REPLY:1} -gt 0 ] && read -r -N $[${REPLY:1}+2] -u "${FD}" # read again to get the value itself 46 | ARGV=( "${REPLY:0:(-2)}" );; 47 | :*) # integer message 48 | ARGV=( "${REPLY:1}" );; 49 | \**) # bulk reply - recursive based on number of messages 50 | unset ARGV 51 | for ((ARGC="${REPLY:1}";${ARGC}>0;ARGC--)); do 52 | ARGV=("${ARGV[@]}" $(redis-client ${FD})) 53 | done;; 54 | +*) # standard message 55 | ARGV=( "${REPLY:1}" );; 56 | *) # wtf? just in case... 57 | ARGV=( "${ARGV[@]}" "${REPLY}" );; 58 | esac 59 | printf "%s\n" "${ARGV[@]}" 60 | else 61 | printf "ERROR: Recursive function call limit.\n" 62 | fi 63 | } 64 | -------------------------------------------------------------------------------- /redis-pubsub-test: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # https://github.com/caquino/redis-bash 3 | # run this file passing the channel to subscribe as argument 4 | # ./redis-pubsub-test testchannel 5 | # and on another shell publish a message on the same channel 6 | # ./redis-bash-cli -h localhost PUBLISH testchannel Hello World 7 | source /usr/share/redis-bash/redis-bash-lib 2> /dev/null 8 | if [ $? -ne 0 ]; then 9 | LIBFOLDER=${0%/${0##*/}} 10 | source ${LIBFOLDER}/redis-bash-lib 2> /dev/null 11 | if [ $? -ne 0 ]; then 12 | echo "can't find redis-bash-lib in /usr/share/redis-bash or ${LIBFOLDER}" 13 | exit 127 14 | fi 15 | fi 16 | REDISHOST=localhost 17 | REDISPORT=6379 18 | while getopts ":h:p:" opt 19 | do 20 | case ${opt} in 21 | h) REDISHOST=${OPTARG};; 22 | p) REDISPORT=${OPTARG};; 23 | esac 24 | done 25 | shift $((${OPTIND} - 1)) 26 | while true 27 | do 28 | exec 5>&- 29 | if [ "${REDISHOST}" != "" ] && [ "${REDISPORT}" != "" ] 30 | then 31 | exec 5<>/dev/tcp/${REDISHOST}/${REDISPORT} # open fd 32 | else 33 | echo "Wrong arguments" 34 | exit 255 35 | fi 36 | redis-client 5 SUBSCRIBE ${1} > /dev/null # subscribe to the pubsub channel in fd 5 37 | while true 38 | do 39 | unset ARGV 40 | OFS=${IFS};IFS=$'\n' # split the return correctly 41 | ARGV=($(redis-client 5)) 42 | IFS=${OFS} 43 | if [ "${ARGV[0]}" = "message" ] && [ "${ARGV[1]}" = "${1}" ] 44 | then 45 | echo "Message from pubsub channel: ${ARGV[2]}" 46 | elif [ -z ${ARGV} ] 47 | then 48 | sleep 1 49 | break 50 | fi 51 | done 52 | done 53 | --------------------------------------------------------------------------------