Querying data from Redis database

138 views
Skip to first unread message

rkell...@gmail.com

unread,
Oct 26, 2017, 10:15:10 PM10/26/17
to Redis DB
Greetings all,

<Please redirect me if this is not the correct place to post this type of topic>

I am new to Redis and would like some pointers on how to retrieve data from a Redis DB.  

Background:  We have a number of servers running lots of LXC containers, and we would like to use Redis to track these containers and their state data.  Each container has a container name, associated IP, state (running/stopped), data created, etc.  The goal is to populate a redis database and run queries using that data.  For example, we need to get a list of all containers in RUNNING state, get a list of containers running on SERVER_01, etc

I have setup a Redis server v4.0.2 on Ubuntu 16.04 and have installed the redis-cli packages on our LXD servers.  Next, I wrote a simple script to create the data we want to collect - the output is below.  The has index value is a combination of the letters "CS" (short for ContainerServer) plus the IP and container name (ie: CS:1.3.5.153_content-mustang).  Using the Redis Desktop Manager program, I can see all the entries in the Redis database with the corresponding key/values (please see the screenshot).  Here is an example of what my script outputs:

------------------------------------------------
redis-cli -h 1.3.5.150 HMSET CS:1.3.5.153_content-mustang  CNAME "content-mustang"  CIP "1.3.5.221 (eth0)"  State "RUNNING"  Created "2017/10/26 16:37 UTC"  Last_Used "2017/10/26 16:37 UTC"  OS "Alpine"  OS_Ver "3.6"  Server lxd-03 Server_IP 1.3.5.153

redis-cli -h 1.3.5.150 HMSET CS:1.3.5.153_direct-mutt  CNAME "direct-mutt"  CIP "1.3.5.209 (eth0)"  State "STOPPED"  Created "2017/10/26 16:36 UTC"  Last_Used "2017/10/26 16:36 UTC"  OS "Alpine"  OS_Ver "3.6"  Server lxd-03 Server_IP 1.3.5.153

redis-cli -h 1.3.5.150 HMSET CS:1.3.5.153_fun-mantis  CNAME "fun-mantis"  CIP "1.3.5.213 (eth0)"  State "RUNNING"  Created "2017/10/26 16:36 UTC"  Last_Used "2017/10/26 16:36 UTC"  OS "Alpine"  OS_Ver "3.6"  Server lxd-03 Server_IP 1.3.5.153

redis-cli -h 1.3.5.150 HMSET CS:1.3.5.153_great-impala  CNAME "great-impala"  CIP "1.3.5.205 (eth0)"  State "RUNNING"  Created "2017/10/26 16:36 UTC"  Last_Used "2017/10/26 16:36 UTC"  OS "CentOS"  OS_Ver "6.5"  Server lxd-03 Server_IP 1.3.5.153

redis-cli -h 1.3.5.150 HMSET CS:1.3.5.153_optimal-javelin  CNAME "optimal-javelin"  CIP "1.3.5.201 (eth0)"  State "RUNNING"  Created "2017/10/26 16:23 UTC"  Last_Used "2017/10/26 16:36 UTC"  OS "Alpine"  OS_Ver "3.6"  Server lxd-03 Server_IP 1.3.5.153
------------------------------------------------


Now, I would like to start pulling data from the Redis server, however, I can't find the right syntax.  Using the example data above, I would like to find all containers in RUNNING state, or all containers running Alpine OS, etc. 

Thanks in advance,

-Ron
screenshot_07.png

Jesús Gabriel y Galán

unread,
Nov 14, 2017, 6:57:01 AM11/14/17
to redi...@googlegroups.com
I think you should read this article:

https://redis.io/topics/indexes

Hope this helps,

Jesus.
> --
> You received this message because you are subscribed to the Google Groups
> "Redis DB" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to redis-db+u...@googlegroups.com.
> To post to this group, send email to redi...@googlegroups.com.
> Visit this group at https://groups.google.com/group/redis-db.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages