/* -*- Mode: C; tab-width: 4 -*- */
/*
+----------------------------------------------------------------------+
| PHP Version 5 |
+----------------------------------------------------------------------+
| Copyright (c) 1997-2009 The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| http://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Original Author: Michael Grunder <michael.grunder@gmail.com |
| Maintainer: Nicolas Favre-Felix <n.favre-felix@owlient.eu> |
+----------------------------------------------------------------------+
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "redis_commands.h"
#include "php_network.h"
#ifndef PHP_WIN32
#include <netinet/tcp.h> /* TCP_KEEPALIVE */
#else
#include <winsock.h>
#endif
#include <zend_exceptions.h>
/* Georadius sort type */
typedef enum geoSortType {
SORT_NONE,
SORT_ASC,
SORT_DESC
} geoSortType;
/* Georadius store type */
typedef enum geoStoreType {
STORE_NONE,
STORE_COORD,
STORE_DIST
} geoStoreType;
/* Georadius options structure */
typedef struct geoOptions {
int withcoord;
int withdist;
int withhash;
long count;
geoSortType sort;
geoStoreType store;
zend_string *key;
} geoOptions;
/* Local passthrough macro for command construction. Given that these methods
* are generic (so they work whether the caller is Redis or RedisCluster) we
* will always have redis_sock, slot*, and TSRMLS_CC */
#define REDIS_CMD_SPPRINTF(ret, kw, fmt, ...) \
redis_spprintf(redis_sock, slot TSRMLS_CC, ret, kw, fmt, ##__VA_ARGS__)
/* Generic commands based on method signature and what kind of things we're
* processing. Lots of Redis commands take something like key, value, or
* key, value long. Each unique signature like this is written only once */
/* A command that takes no arguments */
int redis_empty_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot,
void **ctx)
{
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "");
return SUCCESS;
}
/* Helper to construct a raw command. Given that the cluster and non cluster
* versions are different (RedisCluster needs an additional argument to direct
* the command) we take the start of our array and count */
int redis_build_raw_cmd(zval *z_args, int argc, char **cmd, int *cmd_len TSRMLS_DC)
{
smart_string cmdstr = {0};
int i;
/* Make sure our first argument is a string */
if (Z_TYPE(z_args[0]) != IS_STRING) {
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"When sending a 'raw' command, the first argument must be a string!");
return FAILURE;
}
/* Initialize our command string */
redis_cmd_init_sstr(&cmdstr, argc-1, Z_STRVAL(z_args[0]), Z_STRLEN(z_args[0]));
for (i = 1; i < argc; i++) {
switch (Z_TYPE(z_args[i])) {
case IS_STRING:
redis_cmd_append_sstr(&cmdstr, Z_STRVAL(z_args[i]),
Z_STRLEN(z_args[i]));
break;
case IS_LONG:
redis_cmd_append_sstr_long(&cmdstr,Z_LVAL(z_args[i]));
break;
case IS_DOUBLE:
redis_cmd_append_sstr_dbl(&cmdstr,Z_DVAL(z_args[i]));
break;
default:
php_error_docref(NULL TSRMLS_CC, E_WARNING,
"Raw command arguments must be scalar values!");
efree(cmdstr.c);
return FAILURE;
}
}
/* Push command and length to caller */
*cmd = cmdstr.c;
*cmd_len = cmdstr.len;
return SUCCESS;
}
smart_string *
redis_build_script_cmd(smart_string *cmd, int argc, zval *z_args)
{
int i;
zend_string *zstr;
if (Z_TYPE(z_args[0]) != IS_STRING) {
return NULL;
}
// Branch based on the directive
if (!strcasecmp(Z_STRVAL(z_args[0]), "flush") || !strcasecmp(Z_STRVAL(z_args[0]), "kill")) {
// Simple SCRIPT FLUSH, or SCRIPT_KILL command
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[0]), Z_STRLEN(z_args[0]));
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "load")) {
// Make sure we have a second argument, and it's not empty. If it is
// empty, we can just return an empty array (which is what Redis does)
if (argc < 2 || Z_TYPE(z_args[1]) != IS_STRING || Z_STRLEN(z_args[1]) < 1) {
return NULL;
}
// Format our SCRIPT LOAD command
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
redis_cmd_append_sstr(cmd, "LOAD", sizeof("LOAD") - 1);
redis_cmd_append_sstr(cmd, Z_STRVAL(z_args[1]), Z_STRLEN(z_args[1]));
} else if (!strcasecmp(Z_STRVAL(z_args[0]), "exists")) {
// Make sure we have a second argument
if (argc < 2) {
return NULL;
}
/* Construct our SCRIPT EXISTS command */
REDIS_CMD_INIT_SSTR_STATIC(cmd, argc, "SCRIPT");
redis_cmd_append_sstr(cmd, "EXISTS", sizeof("EXISTS") - 1);
for (i = 1; i < argc; ++i) {
zstr = zval_get_string(&z_args[i]);
redis_cmd_append_sstr(cmd, ZSTR_VAL(zstr), ZSTR_LEN(zstr));
zend_string_release(zstr);
}
} else {
/* Unknown directive */
return NULL;
}
return cmd;
}
/* Generic command where we just take a string and do nothing to it*/
int redis_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock, char *kw,
char **cmd, int *cmd_len, short *slot, void **ctx)
{
char *arg;
strlen_t arg_len;
// Parse args
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &arg, &arg_len)
==FAILURE)
{
return FAILURE;
}
// Build the command without molesting the string
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "s", arg, arg_len);
return SUCCESS;
}
/* Key, long, zval (serialized) */
int redis_key_long_val_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot,
void **ctx)
{
char *key = NULL;
strlen_t key_len;
zend_long expire;
zval *z_val;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "slz", &key, &key_len,
&expire, &z_val) == FAILURE)
{
return FAILURE;
}
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "klv", key, key_len, expire, z_val);
return SUCCESS;
}
/* Generic key, long, string (unserialized) */
int redis_key_long_str_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, char **cmd, int *cmd_len, short *slot,
void **ctx)
{
char *key, *val;
strlen_t key_len, val_len;
zend_long lval;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sls", &key, &key_len,
&lval, &val, &val_len) == FAILURE)
{
return FAILURE;
}
*cmd_len = REDIS_CMD_SPPRINTF(cmd, kw, "kds", key, key_len, (int)lval, val, val_len);
return SUCCESS;
}
/* Generic command construction when we just take a key and value */
int redis_kv_cmd(INTERNAL_FUNCTION_PARAMETERS, RedisSock *redis_sock,
char *kw, ch
没有合适的资源?快使用搜索试试~ 我知道了~
完全备份、增量备份、差异备份、binlog日志
0 下载量 173 浏览量
2024-01-17
17:26:20
上传
评论
收藏 236KB TGZ 举报
温馨提示
共43个文件
h:12个
c:10个
php:8个
完全备份、增量备份、差异备份、binlog日志
资源推荐
资源详情
资源评论
收起资源包目录
redis-cluster-4.3.0.tgz (43个子文件)
redis-4.3.0
liblzf
README 1KB
lzf_d.c 6KB
LICENSE 1KB
lzf.h 5KB
lzf_c.c 9KB
lzfP.h 7KB
README.markdown 113KB
config.m4 5KB
INSTALL.markdown 3KB
cluster_library.c 79KB
library.h 8KB
redis_cluster.c 104KB
redis_commands.h 13KB
tests
TestSuite.php 6KB
startSession.php 1KB
make-cluster.sh 3KB
RedisClusterTest.php 24KB
TestRedis.php 2KB
RedisArrayTest.php 18KB
getSessionData.php 560B
mkring.sh 731B
RedisTest.php 246KB
regenerateSessionId.php 2KB
arrays.markdown 10KB
library.c 78KB
php_redis.h 8KB
redis_array_impl.c 42KB
redis_commands.c 127KB
crc16.h 4KB
cluster_library.h 17KB
common.h 35KB
redis_session.h 547B
config.w32 923B
cluster.markdown 10KB
redis.c 114KB
CREDITS 204B
redis_session.c 38KB
redis_array_impl.h 1KB
redis_cluster.h 11KB
redis_array.c 43KB
COPYING 3KB
redis_array.h 2KB
package.xml 30KB
共 43 条
- 1
资源评论
Mick方
- 粉丝: 1105
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功