mport Redisr_server= Redis. Redis ('localhost')#This line creates a new Redis object and #connects to our Redis serverR_server.set ('Test_key','Test_value')#With the created Redis object we can #submits Redis commands as its methods Print 'Previous Set Key'+ R_server.get ('Test_key')#The previous set key is fetched" "in the previous example you saw that we introduced a redisdata type:the string, now we'll set an integer and try to Increase its value using Redis object built-in methods" "R_server.set ('counter', 1)#set an integer to a keyR_SERVER.INCR ('counter')#We increase the key value by 1, have to is intPrint 'The counter was increased!'+ R_server.get ('counter')#Notice the key is increased nowR_SERVER.DECR ('counter')#We decrease the key value by 1, have to is intPrint 'The counter was decreased!'+ R_server.get ('counter')#The key is back to normal" "Now we is ready-to-jump-to- another Redis data type, the list, notice that they is exactly mapped to Python lists Once you get them" "R_server.rpush ('List1','element1')#we use the List1 as a list and push element1 as its elementR_server.rpush ('List1','Element2')#assign another element to our listR_server.rpush ('List2','Element3')#The samePrint 'Our Redis list len is:%s'% R_server.llen ('List1')#With Llen we get my redis list size right from RedisPrint 'At Pos 1 of our list is:%s'% R_server.lindex ('List1', 1)#With lindex, we query Redis to tell us which element are at POS 1 for our list" "sets perform identically to the built in Python set type. Simply, sets is lists but the can only has unique values." "R_server.sadd ("Set1","El1") R_server.sadd ("Set1","El2") R_server.sadd ("Set1","El2")Print 'The member of our set is:%s'% R_server.smembers ("Set1")" "basically our Redis client can does any command supported by Redis, check out Redis documentation for available commands For your server" "
Redis Client Python Usage