Skip to content

Commit

Permalink
moving to select based impl
Browse files Browse the repository at this point in the history
  • Loading branch information
toymachine committed Apr 5, 2010
1 parent e92021c commit 48b8728
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 122 deletions.
16 changes: 8 additions & 8 deletions .cproject
Expand Up @@ -30,15 +30,15 @@
<option id="gnu.c.compiler.exe.debug.option.debugging.level.1138410845" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.warnings.pedantic.549157664" name="Pedantic (-pedantic)" superClass="gnu.c.compiler.option.warnings.pedantic" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.misc.other.137855241" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -std=gnu99" valueType="string"/>
<option id="gnu.c.compiler.option.include.paths.1814414852" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<option id="gnu.c.compiler.option.include.paths.1814414852" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/libredis/include}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1445887938" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.894027643" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug">
<option id="gnu.c.link.option.libs.260277660" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="event"/>
<listOptionValue builtIn="false" value="m"/>
<listOptionValue builtIn="false" value="rt"/>
</option>
<option defaultValue="true" id="gnu.c.link.option.shared.175267329" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1086609857" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
Expand Down Expand Up @@ -427,15 +427,15 @@
</option>
<option id="gnu.c.compiler.option.warnings.pedantic.389505680" name="Pedantic (-pedantic)" superClass="gnu.c.compiler.option.warnings.pedantic" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.misc.other.808614396" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -std=gnu99" valueType="string"/>
<option id="gnu.c.compiler.option.include.paths.1705031954" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<option id="gnu.c.compiler.option.include.paths.1705031954" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/libredis/include}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.2042413195" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.699059502" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release">
<option id="gnu.c.link.option.libs.1845595822" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="event"/>
<listOptionValue builtIn="false" value="m"/>
<listOptionValue builtIn="false" value="rt"/>
</option>
<option defaultValue="true" id="gnu.c.link.option.shared.488151747" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1004678549" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
Expand Down Expand Up @@ -825,15 +825,15 @@
<option id="gnu.c.compiler.option.warnings.pedantic.820057054" name="Pedantic (-pedantic)" superClass="gnu.c.compiler.option.warnings.pedantic" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.misc.other.42614541" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -std=gnu99" valueType="string"/>
<option id="gnu.c.compiler.option.debugging.gprof.936284882" name="Generate gprof information (-pg)" superClass="gnu.c.compiler.option.debugging.gprof" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.include.paths.1547348632" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<option id="gnu.c.compiler.option.include.paths.1547348632" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/libredis/include}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.603495480" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.release.1887659273" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.release">
<option id="gnu.c.link.option.libs.585879361" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="event"/>
<listOptionValue builtIn="false" value="m"/>
<listOptionValue builtIn="false" value="rt"/>
</option>
<option id="gnu.c.link.option.debugging.gprof.1471329691" name="Generate gprof information (-pg)" superClass="gnu.c.link.option.debugging.gprof" value="true" valueType="boolean"/>
<option defaultValue="true" id="gnu.c.link.option.shared.402921570" name="Shared (-shared)" superClass="gnu.c.link.option.shared" valueType="boolean"/>
Expand Down Expand Up @@ -1226,15 +1226,15 @@
<option id="gnu.c.compiler.exe.debug.option.debugging.level.1614170341" name="Debug Level" superClass="gnu.c.compiler.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<option id="gnu.c.compiler.option.warnings.pedantic.1143534917" name="Pedantic (-pedantic)" superClass="gnu.c.compiler.option.warnings.pedantic" value="true" valueType="boolean"/>
<option id="gnu.c.compiler.option.misc.other.213672354" name="Other flags" superClass="gnu.c.compiler.option.misc.other" value="-c -fmessage-length=0 -std=gnu99" valueType="string"/>
<option id="gnu.c.compiler.option.include.paths.2006113487" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<option id="gnu.c.compiler.option.include.paths.2006113487" name="Include paths (-I)" superClass="gnu.c.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/libredis/include}&quot;"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1952509459" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.exe.debug.661523374" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.exe.debug">
<option id="gnu.c.link.option.libs.659942975" name="Libraries (-l)" superClass="gnu.c.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="event"/>
<listOptionValue builtIn="false" value="m"/>
<listOptionValue builtIn="false" value="rt"/>
</option>
<option id="gnu.c.link.option.shared.1923855540" name="Shared (-shared)" superClass="gnu.c.link.option.shared"/>
<inputType id="cdt.managedbuild.tool.gnu.c.linker.input.1784674827" superClass="cdt.managedbuild.tool.gnu.c.linker.input">
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -4,7 +4,7 @@ REDIS_HOME=$(CURDIR)

libredis: src/alloc.o src/batch.o src/connection.o src/ketama.o src/md5.o src/module.o src/parser.o src/buffer.o
mkdir -p lib
gcc -shared -o"lib/libredis.so" ./src/alloc.o ./src/batch.o ./src/buffer.o ./src/connection.o ./src/ketama.o ./src/md5.o ./src/module.o ./src/parser.o -levent -lm -lrt
gcc -shared -o"lib/libredis.so" ./src/alloc.o ./src/batch.o ./src/buffer.o ./src/connection.o ./src/ketama.o ./src/md5.o ./src/module.o ./src/parser.o -lm -lrt

php_ext:
rm -rf /tmp/libredis_php
Expand Down
40 changes: 22 additions & 18 deletions redis.py
Expand Up @@ -5,29 +5,36 @@
import sys
if '--debug' in sys.argv:
libredis = cdll.LoadLibrary("Debug/libredis.so")
else:
elif '--release' in sys.argv:
libredis = cdll.LoadLibrary("Release/libredis.so")
else:
libredis = cdll.LoadLibrary("lib/libredis.so")

libredis.Module_init()
libredis.Module_init(0)
atexit.register(libredis.Module_free)

DEFAULT_TIMEOUT_MS = 3000

class Connection(object):
def __init__(self, addr):
self._connection = libredis.Connection_new(addr)

def get(self, key):
def get(self, key, timeout_ms = DEFAULT_TIMEOUT_MS):
batch = Batch()
batch.writef("GET %s\r\n", key)
batch.add_command()
self.execute(batch)
reply = batch.pop_reply()
return reply.value
batch.write("GET %s\r\n" % key, 1)
return self._simple_exec(batch, timeout_ms)

def execute(self, batch, dispatch = True):
libredis.Connection_execute(self._connection, batch._batch)
if dispatch:
libredis.Module_dispatch()

def _simple_exec(self, batch, timeout_ms):
executor = libredis.Executor_new()
try:
libredis.Executor_add(executor, self._connection, batch._batch)
libredis.Executor_execute(executor, timeout_ms)
finally:
libredis.Executor_free(executor)
#reply = batch.pop_reply()
#return reply.value
return "BlaatTODO"

def free(self):
libredis.Connection_free(self._connection)
self._connection = None
Expand Down Expand Up @@ -128,12 +135,9 @@ class Batch(object):
def __init__(self):
self._batch = libredis.Batch_new()

def writef(self, format, *args):
libredis.Batch_writef(self._batch, format, *args)
def write(self, cmd, nr_commands):
libredis.Batch_write(self._batch, cmd, len(cmd), nr_commands)

def add_command(self):
libredis.Batch_add_command(self._batch)

def next_reply(self):
return Reply.from_next(self)

Expand Down

0 comments on commit 48b8728

Please sign in to comment.