memcached_test.d 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import memcached4d;
  2. import std.stdio : writeln;
  3. import vibe.core.core;
  4. import vibe.http.router;
  5. import vibe.http.server;
  6. import vibe.http.fileserver;
  7. import vibe.http.websockets;
  8. import vibe.core.log;
  9. import mustache;
  10. alias MustacheEngine!(string) Mustache;
  11. void memcached_test(HTTPServerRequest req, HTTPServerResponse res){
  12. auto cache = memcachedConnect("127.0.0.1:11211");
  13. writeln("get test1 = ", cache.get!string("test1"));
  14. string v1 = "value1 = 🔥🦀";
  15. if(cache.store("test1", v1) == RETURN_STATE.SUCCESS ){
  16. writeln("stored successfully");
  17. writeln("get stored: ", cache.get!string("test1") );
  18. }else{
  19. writeln("not stored");
  20. }
  21. string result = cache.get!string("test1");
  22. writeln("get test1 = ", result);
  23. writeln(cache.del("test1"));
  24. Mustache mustache2;
  25. auto context2 = new Mustache.Context;
  26. mustache2.path = "priv/folder2";
  27. mustache2.ext = "dtl";
  28. context2["param2"] = "blah blah blah ";
  29. Mustache mustache;
  30. auto context = new Mustache.Context;
  31. mustache.path = "priv";
  32. mustache.ext = "dtl";
  33. //context.useSection("boolean");
  34. //assert(mustache.renderString(" {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n", context) == " YES\n GOOD\n");
  35. //{{escaped_html_tags}}
  36. //{{{not_escaped_html_tags}}}
  37. //{{#repo}}<b>{{name}}</b>{{/repo}}
  38. //{{^repo}}No repos :({{/repo}}
  39. // to
  40. //No repos :(
  41. context["lang"] = "en";
  42. context["number1"] = 42;
  43. context.useSection("maybe1");
  44. context["part1"] = mustache2.render("part1", context2);
  45. context["result1"] = "Hello, World!\n" ~ result;
  46. res.headers["Content-Type"] = "text/html; charset=utf-8";
  47. //res.writeBody("Hello, World!\n" ~ result);
  48. res.writeBody( mustache.render("main", context) );
  49. }