Forum Discussion

Kris82_167334's avatar
Kris82_167334
Icon for Nimbostratus rankNimbostratus
Apr 30, 2015

Checking session subtable in IRule

What is the correct way of checking if a session subtable with given name exists in IRule ?

 

In the use case I am working I need to distinguish between a subtable which has no rows and a subtable which has not been created.

 

Appreciate any help with this.

 

Thanks

 

4 Replies

  • Hmmm, the only thing I can think of is to add a test row every time you create a table. Then you can do a count for a table that is empty (1 entry) and use an if with an attempt to increment the test row value, it'll return 0 if the subtable doesn't exist. Make sense?

     

  • Hmmm, the only thing I can think of is to add a test row every time you create a table. Then you can do a count for a table that is empty (1 entry) and use an if with an attempt to increment the test row value, it'll return 0 if the subtable doesn't exist. Make sense?

     

  • I don't think it is possible to distinguish, why would you need to do that? I believe a subtable with all keys removed simply ceases to exist...

     

    if {[table keys -subtable sometable -count] ==0} { subtable is empty or does not exist }

     

    if you really need to do this then you can place a dummy key in your subtable and ccheck for it using "-mustexist" option.

     

    Extract from Wiki: https://devcentral.f5.com/wiki/iRules.table.ashx?lc=1

     

    " If -mustexist is specified, and the key does not already exist, no action will be taken, and an empty string will be returned. Cannot be specified with -excl.If -excl is specified, and the key already exists, the key will not be inserted, and the existing value will be returned. Cannot be specified with -mustexist. "

     

    Hope this helps,

     

    Sam

     

  • Thanks for the answers. That is how I have done it so far, by placing a dummy row. My criterion is a typical one of counter number of requests in X minute interval window, however I want to differentiate between a user who is coming in for first time to one who has visited before X minutes.

     

    I was looking if there is a more cleaner approach for testing existence of a table, rather than putting in a dummy row with indefinite lifetime.

     

    From answers, Looks like it is not possible.