I am currently stuck creating a module that uses the [Redis 
module](https://github.com/nim-lang/redis) asynchronously. I don't really know 
how to solve this so maybe you could help me. Here is what I imagined to do:
    
    
    import redis, asyncdispatch
    
    # I need this proc to instantiate "db" and other stuff that uses "await"
    proc instantiate {.async, discardable.} =
      const
        port = 6379.Port
        domain = "127.0.0.1"
      
      let
        db = await openAsync(domain, port)
      
      var
        keystring: string = ""
    
    # I need this proc to be within the instantiate proc, so it can use the 
"db" var, since it is not available outside the instantiate proc
      proc rsearch(pattern: string) {.async, discardable.} =
        keystring = repr(await db.keys(pattern))
        keystring.echo
    
    # Here is where I am stuck
    # In theory, this should be callable from the .nim that imported this module
    rsearch("test")
    
    # But the proc within the proc is only callable from within the initial 
instantiate proc, which is useless
    
    # I tried different ways of establishing what I wish for but failed
    # Above code is the result of the last thing I tried
    
    
    
    Run

Probably easy to solve for you, but I couldn't wrap my head around this.

Reply via email to