I am currently designing an auto FIFO queue using redis for my own 3d-printer, i am a new towards python scripting and redis. Any better ideas from you is appreciated.
I am having trouble in creating a python script to check do a check if a key value is available or not.
Currently my python script is
import redis
import os
import time
r = redis.StrictRedis(host='172.16.114.54', port=6379, db=0)
if r.lrange('stlfile',0 ,0) == None:
print 'there is no key'
else:
print r.lrange('stlfile',0 ,0)
Output:
root@user:~/scripts# python autoslice.py
['172.16.114.162/registered/uploads/teemo.stl']
while my redis have these values
172.16.114.54:6379> lrange stlfile 0 -1
1) "172.16.114.162/registered/uploads/teemo.stl"
2) "172.16.114.162/registered/uploads/hunter_knife.stl"
i currently can do a r.lrange('stlfile', 0,0) and my 1st key value will output.
1st question : is how do i do a python script to check if a value is there or a 'nil' appear? Should i do a string check?
2nd question : my value r.lrange('stlfile', 0,0) appeared, which is what i wanted but without the ['xxx'] (quotes), how do i remove them automately? (only leaving the xxx value)
i have tried to remove my quotes using this but to no avail python How can I strip first and last double quotes
string = string[1:-1]
>>>r = redis.StrictRedis(host='172.16.114.54', port=6379, db=0)
>>>string = r.lrange ('stlfile', 0, 0)
>>>x = string[1:-1]
>>>print x
[]
not too sure why my output is [] instead of string without quotes