Permalink
Browse files

Added key prefix.

  • Loading branch information...
1 parent b1142fe commit 2e7e610640b3e951a9ab9f2cf84ee9e478e091cc @nicolasff nicolasff committed Dec 28, 2010
Showing with 199 additions and 28 deletions.
  1. +4 −0 common.h
  2. +22 −2 library.c
  3. +2 −0 library.h
  4. +171 −26 redis.c
View
@@ -24,6 +24,7 @@
/* options */
#define REDIS_OPT_SERIALIZER 1
+#define REDIS_OPT_PREFIX 2
/* serializers */
#define REDIS_SERIALIZER_NONE 0
@@ -149,6 +150,9 @@ typedef struct {
int serializer;
+ char *prefix;
+ int prefix_len;
+
redis_mode mode;
fold_item *head;
fold_item *current;
View
@@ -749,8 +749,8 @@ PHPAPI RedisSock* redis_sock_create(char *host, int host_len, unsigned short por
{
RedisSock *redis_sock;
- redis_sock = emalloc(sizeof *redis_sock);
- redis_sock->host = emalloc(host_len + 1);
+ redis_sock = ecalloc(1, sizeof(RedisSock));
+ redis_sock->host = ecalloc(host_len + 1, 1);
redis_sock->stream = NULL;
redis_sock->status = REDIS_SOCK_STATUS_DISCONNECTED;
@@ -1034,6 +1034,9 @@ PHPAPI int redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz TSRMLS_D
*/
PHPAPI void redis_free_socket(RedisSock *redis_sock)
{
+ if(redis_sock->prefix) {
+ efree(redis_sock->prefix);
+ }
efree(redis_sock->host);
efree(redis_sock);
}
@@ -1140,5 +1143,22 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
}
return 0;
}
+
+PHPAPI int
+redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_CC) {
+ if(redis_sock->prefix == NULL || redis_sock->prefix_len == 0) {
+ return 0;
+ }
+
+ int ret_len = redis_sock->prefix_len + *key_len;
+ char *ret = ecalloc(1 + ret_len, 1);
+ memcpy(ret, redis_sock->prefix, redis_sock->prefix_len);
+ memcpy(ret + redis_sock->prefix_len, *key, *key_len);
+
+ *key = ret;
+ *key_len = ret_len;
+ return 1;
+}
+
/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */
View
@@ -33,6 +33,8 @@ PHPAPI void redis_free_socket(RedisSock *redis_sock);
PHPAPI int
redis_serialize(RedisSock *redis_sock, zval *z, char **val, int *val_len TSRMLS_CC);
+PHPAPI int
+redis_key_prefix(RedisSock *redis_sock, char **key, int *key_len TSRMLS_CC);
PHPAPI int
redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **return_value TSRMLS_CC);
Oops, something went wrong.

0 comments on commit 2e7e610

Please sign in to comment.