Use Redis to define a List
Description
Redis can be used to maintain named lists.
Entries are added to a list at either the 'left', by calling LPush, or at the 'right' by calling RPush.
dim redis as extension::RedisClient = extension::RedisClient::CreateClient()
dim list as extension::RedisResult
redis.LPush("GroceryCart","Bannanas")
redis.LPush("GroceryCart","Apples")
redis.LPush("GroceryCart","Milk")The LRange method reads the list from the from 'left' to 'right'.
Note that the List returns a type of 'Array', and while the valueString contains a cr-lf delimited list of the entries, the individual entries can be read by calling the GetItem method on the RedisResult that is returned.
list = redis.LRange("GroceryCart")
? list.type
= "Array"
? list.valueString
= Milk
Apples
Bannanas
dim item as extension::RedisResult
item = list.GetItem(1)
? item.valueString
= "Milk"
item = list.GetItem(2)
? item.valueString
= "Apples"
item = list.GetItem(3)
? item.valueString
= "Bannanas"To remove items from the left, use the LPop method.
item = redis.LPop("GroceryCart")
? item.valueString
= "Milk"
list = redis.LRange("GroceryCart")
? list.type
= "Array"
? list.valueString
= Apples
BannanasThe remove items from the right, use the RPop method.
item = redis.RPop("GroceryCart")
? item.valueString
= "Bannanas"
list = redis.LRange("GroceryCart")
? list.type
= "Array"
? list.valueString
= "Apples"To delete the entire list, the Del method can be called, just as it can be called for Simple 'keys'.
redis.Del("GroceryCart")