mirror of
https://github.com/fluencelabs/redis
synced 2025-04-25 02:22:13 +00:00
Scripting: native lua.exists() implementation.
This was a test to check how much faster native implementation would be. In initial tests it does not look like is this huge win. After all this is at least in part obvious. Now scripting.c tries to avoid allocations of argument vectors, and turning ":1" accumulated in the client buffer into a Lua type is a fast operation.
This commit is contained in:
parent
2bf27c3361
commit
9545957a67
@ -458,6 +458,35 @@ int luaRedisPCallCommand(lua_State *lua) {
|
||||
return luaRedisGenericCommand(lua,0);
|
||||
}
|
||||
|
||||
int luaExistsCommand(lua_State *lua) {
|
||||
int argc = lua_gettop(lua);
|
||||
redisClient *c = server.lua_client;
|
||||
char *obj_s;
|
||||
size_t obj_len;
|
||||
robj *key, *val;
|
||||
|
||||
/* Require at least one argument */
|
||||
if (argc != 1) {
|
||||
luaPushError(lua,
|
||||
"redis.exists() needs exactly one argument");
|
||||
return 1;
|
||||
}
|
||||
|
||||
obj_s = (char*)lua_tolstring(lua,1,&obj_len);
|
||||
if (obj_s == NULL) {
|
||||
luaPushError(lua,
|
||||
"redis.exists() argument must be a string");
|
||||
return 1;
|
||||
}
|
||||
|
||||
key = createStringObject(obj_s,obj_len);
|
||||
val = lookupKeyRead(c->db,key);
|
||||
decrRefCount(key);
|
||||
|
||||
lua_pushnumber(lua,val != NULL);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* This adds redis.sha1hex(string) to Lua scripts using the same hashing
|
||||
* function used for sha1ing lua scripts. */
|
||||
int luaRedisSha1hexCommand(lua_State *lua) {
|
||||
@ -664,6 +693,11 @@ void scriptingInit(void) {
|
||||
lua_pushcfunction(lua,luaRedisPCallCommand);
|
||||
lua_settable(lua,-3);
|
||||
|
||||
/* redis.exists */
|
||||
lua_pushstring(lua,"exists");
|
||||
lua_pushcfunction(lua,luaExistsCommand);
|
||||
lua_settable(lua,-3);
|
||||
|
||||
/* redis.log and log levels. */
|
||||
lua_pushstring(lua,"log");
|
||||
lua_pushcfunction(lua,luaLogCommand);
|
||||
|
Loading…
x
Reference in New Issue
Block a user