I'm doing some validations on Redis using redis-cli with the following command
redis-cli --scan --pattern XXX:YYY:* | sort
XXX:YYY:126
XXX:YYY:13
XXX:YYY:1369
XXX:YYY:139
XXX:YYY:15
XXX:YYY:16
XXX:YYY:1657
XXX:YYY:17
XXX:YYY:2341
XXX:YYY:2349
XXX:YYY:2353
XXX:YYY:2725
XXX:YYY:2825
XXX:YYY:2837
XXX:YYY:2894
XXX:YYY:2925
XXX:YYY:2933
XXX:YYY:3699
XXX:YYY:4219
XXX:YYY:4227
XXX:YYY:4247
XXX:YYY:4451
XXX:YYY:4475
XXX:YYY:4555
However, I need to take specific keys for example
XXX:YYY:3699
XXX:YYY:4475
XXX:YYY:1657
Is it there a way to still use the initial pattern and do something like
XXX:YYY:* AND (*3899 OR *4475 OR 1657)
thanks
You may use grep for it, there are several patterns here
redis-cli --scan --pattern XXX:YYY:* | sort | grep -e '3699\|4475\|1657'
this will print
XXX:YYY:1657
XXX:YYY:3699
XXX:YYY:4475
Related
I am using redis-cli. I would like to add in a set the numbers 1 all the way to 4,500,000. How can I accomplish this? The docs for sadd do not mention how to do this. If this would involve having to type or paste in every single integer individually, this obviously won't work in the CLI, so is there another way programatically?
You can use a bash script for doing this.
Use 'seq' to create a list of numbers, loop over it and add the current iteration inside the set
#!/bin/bash
for i in `seq 10`
do
redis-cli sadd myset $i
done
In case you need to use redis-cli with host and port details, change the command accordingly: redis-cli -h -p
Once you have this ready in a .sh file, you can run it like:
bash redis_script.sh
When getting all the keys from Redis, like this:
redis.server.com:6379> keys *
1) "z13235jxby03knne1w1gucl5"
Instead of manually copying the long key to execute get z13235jxby03knne1w1gucl5, I'd like to run something like get $(1) (pseudo code) to get the value at position 1, as output by the keys command.
Is this possible, if not, is there any workaround to not have to manually copy paste?
Note, I don't want to solve this with a script, then I prefer just copy and paste it
off the top of my head, I'm not aware of a way from inside the cli.
But, Regardless of any performance implications, you can pipe the cli command lines together , but you have to do it from the shell
redis-cli --raw KEYS "*" | sed -n 1p | xargs redis-cli GET
where the 1 in :
sed -n 1p
is the line number (1-based index) inside KEYS output.
but still you need to do your validations; like making sure the index is withing the nuber of keys returned by the KEYS command all keys are of simple string type ; not sets, hash maps, etc...
I want to be able to execute a number of Impala queries and return the time it took for each query to execute. Using the Impala shell, I can do this with the following command:
impl -q "select count(*) from database.table;"
This gives me the output
Using service name 'impala'
SSL is enabled. Impala server certificates will NOT be verified (set --ca_cert to change)
Connected to *****.************:21000
Server version: impalad version 2.6.0-cdh5.8.3 RELEASE (build c644f476b774db9db87a619628f7a6ecc5f843e0)
Query: select count(*) from database.table
+----------+
| count(*) |
+----------+
| 1130976 |
+----------+
Fetched 1 row(s) in 0.86s
I want to be able to fetch that last line and extract the time. It doesn't really matter how, which is why I haven't tagged a language. I have tried using grep like this:
impl -q "select count(*) from database.table" | grep -Po "\d+\.\d+"
But that does nothing but remove the table. Putting the query in a python script and using subprocess couldn't find impl as a command, and same for scala.
The weird thing is that impala-shell dumps those messages to stderr rather than to stdout, so to fetch the last line, you would have to append a 2>&1 to redirect stderr to stdout
impala-shell -q "query string" 2>&1 | grep -Po "\d+\.\d+(?=s)"
Notice that a positive lookahead (?=s) is probably required to avoid capturing version numbers
I have a long text file of redis commands that I need to execute using the redis command line interface:
e.g.
DEL 9012012
DEL 1212
DEL 12214314
etc.
I can't seem to figure out a way to enter the commands faster than one at a time. There are several hundred thousands lines, so I don't want to just pile them all into one DEL command, they also don't need to all run at once.
the following code works for me with redis 2.4.7 on mac
./redis-cli < temp.redisCmds
Does that satisfy your requirements? Or are you looking to see if there's a way to programmatically do it faster?
If you don't want to make a file, use echo and \n
echo "DEL 9012012\nDEL 1212" | redis-cli
The redis-cli --pipe can be used for mass-insertion. It is available since 2.6-RC4 and in Redis 2.4.14.
For example:
cat data.txt | redis-cli --pipe
More info in: http://redis.io/topics/mass-insert
I know this is an old old thread, but adding this since it seems missed out among other answers, and one that works well for me.
Using heredoc works well here, if you don't want to use echo or explicitly add \n or create a new file -
redis-cli <<EOF
select 15
get a
EOF
Is there any command/tool/script to categorize the bulky output of ec2-describe-images or ec2-describe-instances.
I have a list of around 100 servers with each and every detail. I want to categorize them under suitable headings like - RESERVATION, INSTANCE, BLOCKDEVICE, TAG (whatever category is available on the output).
Did you get this sorted? If not...
run ec2-describe-images with the option --headers to give you the categories
ec2-describe-images --private-key ~/private.key --cert ~/my.crt --region us-west-1 --headers
if you just want certain fields then just pipe the output of the above through the linux command cut picking the fields (columns) you are after. Say you want ImageID, Name and Architecture then these would be fields 2,3 and 8 of the output above. Example.
ec2-describe-images --private-key ~/private.key --cert ~/my.crt --region us-west-1 --headers | cut -f2,3,8 -s
Doing the same for ec2-describe-instances would be similar.
It's a job for awk (or perl, python or other general purpose scripting language).
awk can handle records with various record/field length, can create associative arrays, and it's a reporting language, which is usually installed on every *nix.
Add this to your ~/.bashrc or ~/.bash_profile:
ez-ec2-describe-instances() {
ec2-describe-instances $* --headers | egrep '(ReservationID|running|pending)'|cut -f 2,3,4,6,7,10,12;
}
Logout/login or run ". ~/.bashrc". Then you can use:
$ ez-ec2-describe-instances
ReservationID Owner Groups
i-6f194113 ami-1624987f ec2-107-20-75-13.compute-1.amazonaws.com running t1.micro us-east-1a
You can pass arguments to ez-ec2-describe-instances, just like you would pass them to the regular ec2-describe-instances. E.g.:
$ ez-ec2-describe-instances --region eu-west-1
ReservationID Owner Groups
i-e4fd6eaf ami-c37474b7 ec2-54-246-38-35.eu-west-1.compute.amazonaws.com pending t1.micro eu-west-1a