srinikom/leveldb-server — Issue #2: expose a server object
Author: technoweenie
Created: 2011-11-23 18:54:07+00:00
State: open

I'm not a fan of how everything is inside [`workerThread()`](https://github.com/srinikom/leveldb-server/blob/master/leveldb-server.py#L12). I'd like to do a few things, but I wanted to get your thoughts first:

```python
db = leveldb.LevelDB(options.dbfile)
server = leveldbServer(db)

# custom command
def incr(db, key):
value = int(db.Get(key))
value = value + 1
db.Put(key, str(value))
return value

# binds incr() to the incr command
server.command('incr', incr)

workers = []
for i in xrange(3):
worker = workerThread(context, server)
worker.start()
workers.append(worker)
```

The actual server object shouldn't really care what type of socket it uses. We can run tests (with nose, or something) against a server using a simple req/rep socket, and skip all the broker nonsense. Maybe I want to run the server with something other than xreq in production? Maybe I want to add custom commands to the server?

Thoughts?