PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/wheels/vendor/memcached/memcachedtest.cfm

http://cfwheels.googlecode.com/
ColdFusion | 191 lines | 131 code | 28 blank | 32 comment | 11 complexity | de84e16f569c864d40bc3ef82c1328b7 MD5 | raw file
Possible License(s): Apache-2.0, CPL-1.0
  1. <!-----------
  2. This is a simple test file to show how to use memcached. in order for this to work right, you should
  3. have a memcached instances up. It is initially set up to look for the memcached server on the localhost,
  4. however, the server location can be changed by passing it in to the memcached factory.
  5. the default port for memcached is 11211.
  6. you can actually use this memcached client across multiple memcached servers. You can specify multiple
  7. memcached servers by making them a comma delimited list and sending that in to the init function.
  8. You can also send in an array list of servers.
  9. Be aware, that changing the number of servers or dropping one of the servers out of the server list is likely to
  10. cause a loss of all cached data because it will have to recalculate the positions and locations of the keys.
  11. this will only happen if you init the memcached factory again with more or less servers than you start out with.
  12. ------------>
  13. <cfset variables.memcachedFactory = createObject("component","memcachedFactory").init("127.0.0.1:11211")>
  14. <cfset variables.memcached = variables.memcachedFactory.getmemcached()>
  15. <!--------- setting a long test ------------->
  16. <cfset set1 = variables.memcached.set(key="longTest",value=11111111111111111,expiry="5000")>
  17. <!----------- setting string test ----------->
  18. <cfset set2 = variables.memcached.set(key="simpleval",value="simpleval43466665532",expiry="5000")>
  19. <!------------ setting an int test ---------->
  20. <cfset set3 = variables.memcached.set(key="anothersimpleval",value=8,expiry="5000")>
  21. <!------------ setting array test ------------>
  22. <cfset arrTest = arrayNew(1)>
  23. <Cfset arrTest[1] = "someval">
  24. <Cfset arrTest[2] = "someotherval">
  25. <Cfset arrTest[3] = "someothersecondval">
  26. <cfset set4 = variables.memcached.set(key="arrTest",value=arrTest,expiry="5000")>
  27. <!---------------setting a struct test -------->
  28. <Cfset structTest = structNew()>
  29. <cfset structTest["somekey"] = "someval">
  30. <cfset structTest["someotherkey"] = "someother val">
  31. <Cfset structTest["someothersecondkey"] = "some other second val">
  32. <cfset set5 = variables.memcached.set(key="structTest",value=structTest,expiry="5000")>
  33. <!------------ setting a query test ---------->
  34. <cfset qTest = queryNew("col1,col2,col3")>
  35. <cfset queryAddRow(qTest,1)>
  36. <cfset querysetCell(qTest,"col1","yo")>
  37. <cfset querysetCell(qTest,"col2","adrian")>
  38. <cfset querysetCell(qTest,"col3",8888888)>
  39. <cfset set6 = variables.memcached.set(key="queryTest",value=qTest,expiry="5000")>
  40. <cfoutput>
  41. Here are there responses that were returned. boolean values that are returned when the set completes<br><br>
  42. <br><br>this is the long test - did it set correctly? - <cfdump var="#set1.get()#">
  43. <br><br>this is the String test - did it set correctly? - <cfdump var="#set2.get()#">
  44. <br><br>this is the Integer test - did it set correctly? - <cfdump var="#set3.get()#">
  45. <br><br>this is the Array test - did it set correctly? - <cfdump var="#set4.get()#">
  46. <br><br>this is the Struct test - did it set correctly? - <cfdump var="#set5.get()#">
  47. <br><br>this is the query test - did it set correctly? - <cfdump var="#set5.get()#">
  48. </cfoutput>
  49. <!------------- this is retrieval test to make sure we can get it back out --------->
  50. <!------------ long test ---------->
  51. <cfset test1 = variables.memcached.get("longTest")>
  52. <!------- simple string test ------------>
  53. <cfset test2 = variables.memcached.get("simpleval")>
  54. <!------- int test ------------->
  55. <cfset test3 = variables.memcached.get("anothersimpleval")>
  56. <!---------- array test ------------>
  57. <cfset test4 = variables.memcached.get("arrTest")>
  58. <!--------- struct test ------------>
  59. <cfset test5 = variables.memcached.get("structTest")>
  60. <!--------- query test ------------->
  61. <Cfset test6 = variables.memcached.get("queryTest")>
  62. <!-------- stats test just for fun ---------->
  63. <!----
  64. <Cfset test7 = variables.memcached.getStats()>
  65. ----->
  66. <Cfset test7 = "">
  67. <cfoutput>
  68. --------------------------------------------------------
  69. <br><br>this is the long test - did we retrieve it correctly? - <cfdump var="#test1#">
  70. <br><br>this is the string test - did we retrieve it correctly? - <cfdump var="#test2#">
  71. <br><br>this is the integer test - did we retrieve it correctly? - <cfdump var="#test3#">
  72. <br><br>this is the array test - did we retrieve it correctly? - <Cfdump var="#Test4#">
  73. <br><br> as a comparison, this is what it should look like <br>
  74. -------------------------------------- <br>
  75. <cfdump var="#arrTest#">
  76. <br>
  77. <br><br>this is the struct test - did we retrieve it correctly? - <Cfdump var="#Test5#">
  78. <br><br> as a comparison, this is what it should look like <br>
  79. -------------------------------------- <br>
  80. <cfdump var="#structTest#">
  81. <br>
  82. <br><br>this is the query test - did we retrieve it correctly? - <Cfdump var="#Test6#">
  83. <br><br> as a comparison, this is what it should look like <br>
  84. -------------------------------------- <br>
  85. <cfdump var="#qTest#">
  86. <br>
  87. <br><br>this is the stats test -
  88. <Cfdump var="#Test7.toString()#">
  89. <cfscript>
  90. // keyList = structKeylist(test7);
  91. //newOne = mapToStruct(test7);
  92. </cfscript>
  93. <cfscript>
  94. myendVal = "";
  95. myFutureTask = variables.memcached.asyncGet("queryTest");
  96. if (myFutureTask.isDone()) {
  97. myendVal = myFutureTask.get();
  98. } else {
  99. customSleep(2000);
  100. if (myFutureTask.isDone()) {
  101. myEndVal = myFutureTask.get();
  102. }
  103. }
  104. </cfscript>
  105. <cfdump var="#myFutureTask#">
  106. <cfdump var="#myEndVal#">
  107. <Cfset arrTestVals = arraynew(1)>
  108. <cfset arrayAppend(arrTestVals,"longTest")>
  109. <cfset arrayAppend(arrTestVals,"queryTest")>
  110. <cfset arrayAppend(arrTestVals,"arrTest")>
  111. <cfset arrayAppend(arrTestVals,"structTest")>
  112. <cfset bulkvar = variables.memcached.getBulk(arrTestVals)>
  113. <cfdump var="#bulkvar#">
  114. <cfscript>
  115. myendVal = "";
  116. myFutureTask = variables.memcached.asyncGetBulk(arrTestVals);
  117. if (myFutureTask.isDone()) {
  118. myendVal = myFutureTask.get();
  119. } else {
  120. customSleep(2000);
  121. if (myFutureTask.isDone()) {
  122. myEndVal = myFutureTask.get();
  123. }
  124. }
  125. </cfscript>
  126. <cfdump var="#myFutureTask#">
  127. <cfdump var="#myEndVal#">
  128. </cfoutput>
  129. <cffunction name="customSleep" output="No" returntype="void" hint=
  130. "Pauses execution for a number of milliseconds."
  131. >
  132. <cfargument name="milliseconds" required="Yes" type="numeric"/>
  133. <cfset var thread = CreateObject("java", "java.lang.Thread")/>
  134. <cfset thread.sleep(ARGUMENTS.milliseconds)/>
  135. </cffunction>
  136. <cfscript>
  137. function GetClassHeirarchy(obj){
  138. var thisClass = obj.GetClass();
  139. var sReturn = thisClass.GetName();
  140. do{
  141. thisClass = thisClass.GetSuperClass();
  142. sReturn = sReturn & " EXTENDS: #thisClass.GetName()#";
  143. } while(CompareNoCase(thisClass.GetName(), 'java.lang.Object'));
  144. return sReturn;
  145. }
  146. function mapToStruct(obj) {
  147. var ret = structNew();
  148. if (not obj.isEmpty()) {
  149. do {
  150. key = obj.entrySet().iterator().next();
  151. thisval = obj.get(key);
  152. if (isdefined("thisval")) {
  153. ret[key.toString()] = thisval;
  154. } else {
  155. ret[key.toString()] = "";
  156. }
  157. } while ( obj.entrySet().iterator().hasNext() );
  158. }
  159. }
  160. </cfscript>