Last active
May 9, 2017 11:52
-
-
Save picadoh/072e0fc001f5a2e16914477dec4b32be to your computer and use it in GitHub Desktop.
KeyValueStores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# storage functions | |
db_set () { | |
echo "$1,$2" >> event_store | |
} | |
db_get () { | |
grep "^$1," event_store | sed -e "s/^$1,//" | tail -n 1 | |
} | |
# main flow | |
db_set name luise | |
db_set age 32 | |
db_set name anna | |
db_get name | |
db_get age |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# storage functions | |
db_set () { | |
[[ $(grep "^$1," state_store) ]] && sed -i '' -e "s/^$1,.*/$1,$2/" state_store || echo $1,$2 >> state_store | |
} | |
db_get () { | |
grep "^$1," state_store | sed -e "s/^$1,//" | |
} | |
# main flow | |
db_set name luise | |
db_set age 32 | |
db_set name anna | |
db_get name | |
db_get age |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment