Skip to content
This repository has been archived by the owner on Oct 28, 2023. It is now read-only.

Commit

Permalink
Added redis-style EXISTS command support
Browse files Browse the repository at this point in the history
  • Loading branch information
BohuTANG committed Oct 29, 2011
1 parent bdefd18 commit 655eae0
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
7 changes: 4 additions & 3 deletions README
Expand Up @@ -45,8 +45,9 @@
Start as server
===============
* $./nessdb-server
Now you can use redis-cli(or other redis's clients) to do some "COMMAND" operations(Now support:PING,SET,MSET,GET,MGET,DEL,INFO commands).
Now you can use redis-cli(or other redis's clients) to do some "COMMAND" operations
(Support Redis-Style commands:PING,SET,MSET,GET,MGET,DEL,EXISTS,INFO).

Thanks.
Thanks.

== END OF FILE ==
== END OF FILE ==
6 changes: 6 additions & 0 deletions src/db.c
Expand Up @@ -193,6 +193,12 @@ void *db_get(const char *key)
}
}

int db_exists(const char *key)
{
unsigned int slot=jdb_hash(key)%DB_SLOT;
return btree_get_index(&_btrees[slot],key);
}

void db_remove(const char *key)
{
int result;
Expand Down
2 changes: 1 addition & 1 deletion src/db.h
Expand Up @@ -12,7 +12,7 @@ extern "C" {
void db_init(int bufferpool_size,int isbgsync);

void *db_get(const char *key);

int db_exists(const char *key);
int db_add(const char *key,const char *value);
void db_update(const char *key,const char *value);
void db_remove(const char *key);
Expand Down
8 changes: 8 additions & 0 deletions src/nessdb-server.c
Expand Up @@ -265,6 +265,14 @@ void read_handler(aeEventLoop *el, int fd, void *privdata, int mask)
response_free(resp);
break;
}
case CMD_EXISTS:{
int ret= db_exists(req->argv[1]);
if(ret)
write(fd,":1\r\n",4);
else
write(fd,":-1\r\n",5);
}
break;

default:{
resp=response_new(0,ERR);
Expand Down
1 change: 1 addition & 0 deletions src/request.c
Expand Up @@ -90,6 +90,7 @@ static const struct cmds _cmds[]=
{"mset",CMD_MSET},
{"del",CMD_DEL},
{"info",CMD_INFO},
{"exists",CMD_EXISTS},
{"unknow cmd",CMD_UNKNOW}
};

Expand Down
2 changes: 1 addition & 1 deletion src/request.h
@@ -1,7 +1,7 @@
#ifndef _REQUEST_H
#define _REQUEST_H

typedef enum{CMD_PING,CMD_GET,CMD_MGET,CMD_SET,CMD_MSET,CMD_DEL,CMD_INFO,CMD_UNKNOW}CMD;
typedef enum{CMD_PING,CMD_GET,CMD_MGET,CMD_SET,CMD_MSET,CMD_DEL,CMD_INFO,CMD_EXISTS,CMD_UNKNOW}CMD;

struct cmds{
char method[256];
Expand Down

0 comments on commit 655eae0

Please sign in to comment.