cluster2.lua 1004 B

1234567891011121314151617181920212223242526272829303132
  1. local skynet = require "skynet"
  2. local cluster = require "skynet.cluster"
  3. skynet.start(function()
  4. local proxy = cluster.proxy "db@sdb" -- cluster.proxy("db", "@sdb")
  5. local largekey = string.rep("X", 128*1024)
  6. local largevalue = string.rep("R", 100 * 1024)
  7. skynet.call(proxy, "lua", "SET", largekey, largevalue)
  8. local v = skynet.call(proxy, "lua", "GET", largekey)
  9. assert(largevalue == v)
  10. skynet.send(proxy, "lua", "PING", "proxy")
  11. skynet.fork(function()
  12. skynet.trace("cluster")
  13. print(cluster.call("db", "@sdb", "GET", "a"))
  14. print(cluster.call("db2", "@sdb", "GET", "b"))
  15. cluster.send("db2", "@sdb", "PING", "db2:longstring" .. largevalue)
  16. end)
  17. -- test snax service
  18. skynet.timeout(300,function()
  19. cluster.reload {
  20. db = false, -- db is down
  21. db3 = "127.0.0.1:2529"
  22. }
  23. print(pcall(cluster.call, "db", "@sdb", "GET", "a")) -- db is down
  24. end)
  25. cluster.reload { __nowaiting = false }
  26. local pingserver = cluster.snax("db3", "pingserver")
  27. print(pingserver.req.ping "hello")
  28. end)