@@ -749,8 +749,8 @@ PHPAPI RedisSock* redis_sock_create(char *host, int host_len, unsigned short por
749749{
750750    RedisSock  * redis_sock ;
751751
752-     redis_sock          =  emalloc ( sizeof   * redis_sock );
753-     redis_sock -> host    =  emalloc (host_len  +  1 );
752+     redis_sock          =  ecalloc ( 1 ,  sizeof ( RedisSock ) );
753+     redis_sock -> host    =  ecalloc (host_len  +   1 ,  1 );
754754    redis_sock -> stream  =  NULL ;
755755    redis_sock -> status  =  REDIS_SOCK_STATUS_DISCONNECTED ;
756756
@@ -1034,6 +1034,9 @@ PHPAPI int redis_sock_write(RedisSock *redis_sock, char *cmd, size_t sz TSRMLS_D
10341034 */ 
10351035PHPAPI  void  redis_free_socket (RedisSock  * redis_sock )
10361036{
1037+     if (redis_sock -> prefix ) {
1038+ 		efree (redis_sock -> prefix );
1039+ 	}
10371040    efree (redis_sock -> host );
10381041    efree (redis_sock );
10391042}
@@ -1140,5 +1143,22 @@ redis_unserialize(RedisSock *redis_sock, const char *val, int val_len, zval **re
11401143	}
11411144	return  0 ;
11421145}
1146+ 
1147+ PHPAPI  int 
1148+ redis_key_prefix (RedisSock  * redis_sock , char  * * key , int  * key_len  TSRMLS_CC ) {
1149+ 	if (redis_sock -> prefix  ==  NULL  ||  redis_sock -> prefix_len  ==  0 ) {
1150+ 		return  0 ;
1151+ 	}
1152+ 
1153+ 	int  ret_len  =  redis_sock -> prefix_len  +  * key_len ;
1154+ 	char  * ret  =  ecalloc (1  +  ret_len , 1 );
1155+ 	memcpy (ret , redis_sock -> prefix , redis_sock -> prefix_len );
1156+ 	memcpy (ret  +  redis_sock -> prefix_len , * key , * key_len );
1157+ 
1158+ 	* key  =  ret ;
1159+ 	* key_len  =  ret_len ;
1160+ 	return  1 ;
1161+ }
1162+ 
11431163/* vim: set tabstop=4 softtabstop=4 noexpandtab shiftwidth=4: */ 
11441164
0 commit comments