credis.h   credis.h 
/* credis.h -- a C client library for Redis, public API. /* credis.h -- a C client library for Redis, public API.
* *
* Copyright (c) 2009-2010, Jonas Romfelt <jonas at romfelt dot se> * Copyright (c) 2009-2012, Jonas Romfelt <jonas at romfelt dot se>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are m et: * modification, are permitted provided that the following conditions are m et:
* *
* * Redistributions of source code must retain the above copyright notic e, * * Redistributions of source code must retain the above copyright notic e,
* this list of conditions and the following disclaimer. * this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
skipping to change at line 87 skipping to change at line 87
#define CREDIS_OK 0 #define CREDIS_OK 0
#define CREDIS_ERR -90 #define CREDIS_ERR -90
#define CREDIS_ERR_NOMEM -91 #define CREDIS_ERR_NOMEM -91
#define CREDIS_ERR_RESOLVE -92 #define CREDIS_ERR_RESOLVE -92
#define CREDIS_ERR_CONNECT -93 #define CREDIS_ERR_CONNECT -93
#define CREDIS_ERR_SEND -94 #define CREDIS_ERR_SEND -94
#define CREDIS_ERR_RECV -95 #define CREDIS_ERR_RECV -95
#define CREDIS_ERR_TIMEOUT -96 #define CREDIS_ERR_TIMEOUT -96
#define CREDIS_ERR_PROTOCOL -97 #define CREDIS_ERR_PROTOCOL -97
#define CREDIS_ERR_PUBSUB -98
#define CREDIS_TYPE_NONE 1 #define CREDIS_TYPE_NONE 1
#define CREDIS_TYPE_STRING 2 #define CREDIS_TYPE_STRING 2
#define CREDIS_TYPE_LIST 3 #define CREDIS_TYPE_LIST 3
#define CREDIS_TYPE_SET 4 #define CREDIS_TYPE_SET 4
#define CREDIS_SERVER_MASTER 1 #define CREDIS_SERVER_MASTER 1
#define CREDIS_SERVER_SLAVE 2 #define CREDIS_SERVER_SLAVE 2
typedef enum _cr_aggregate { typedef enum _cr_aggregate {
skipping to change at line 130 skipping to change at line 131
int bgsave_in_progress; int bgsave_in_progress;
long last_save_time; long last_save_time;
int bgrewriteaof_in_progress; int bgrewriteaof_in_progress;
long long total_connections_received; long long total_connections_received;
long long total_commands_processed; long long total_commands_processed;
long long expired_keys; long long expired_keys;
unsigned long hash_max_zipmap_entries; unsigned long hash_max_zipmap_entries;
unsigned long hash_max_zipmap_value; unsigned long hash_max_zipmap_value;
long pubsub_channels; long pubsub_channels;
unsigned int pubsub_patterns; unsigned int pubsub_patterns;
long long keyspace_hits;
long long keyspace_misses;
int vm_enabled; int vm_enabled;
int role; int role;
} REDIS_INFO; } REDIS_INFO;
/* /*
* Connection handling * Connection handling
*/ */
/* `host' is the host to connect to, either as an host name or a IP address , /* `host' is the host to connect to, either as an host name or a IP address ,
* if set to NULL connection is made to "localhost". `port' is the TCP port * if set to NULL connection is made to "localhost". `port' is the TCP port
skipping to change at line 151 skipping to change at line 154
* `timeout' is the time in milliseconds to use as timeout, when connecting * `timeout' is the time in milliseconds to use as timeout, when connecting
* to a Redis server and waiting for reply, it can be changed after a * to a Redis server and waiting for reply, it can be changed after a
* connection has been made using credis_settimeout() */ * connection has been made using credis_settimeout() */
REDIS credis_connect(const char *host, int port, int timeout); REDIS credis_connect(const char *host, int port, int timeout);
/* set Redis server reply `timeout' in millisecs */ /* set Redis server reply `timeout' in millisecs */
void credis_settimeout(REDIS rhnd, int timeout); void credis_settimeout(REDIS rhnd, int timeout);
void credis_close(REDIS rhnd); void credis_close(REDIS rhnd);
void credis_quit(REDIS rhnd); int credis_quit(REDIS rhnd);
int credis_auth(REDIS rhnd, const char *password); int credis_auth(REDIS rhnd, const char *password);
int credis_ping(REDIS rhnd); int credis_ping(REDIS rhnd);
int credis_echo(REDIS rhnd, const char *message, char **reply);
/* if a function call returns error it is _possible_ that the Redis server /* if a function call returns error it is _possible_ that the Redis server
* replied with an error message. It is returned by this function. */ * replied with an error message. It is returned by this function. */
char* credis_errorreply(REDIS rhnd); char* credis_errorreply(REDIS rhnd);
/* /*
* Commands operating on all the kind of values * Commands operating on all the kind of values
*/ */
/* returns -1 if the key doesn't exists and 0 if it does */ /* returns -1 if the key doesn't exists and 0 if it does */
int credis_exists(REDIS rhnd, const char *key); int credis_exists(REDIS rhnd, const char *key);
skipping to change at line 213 skipping to change at line 218
int credis_flushdb(REDIS rhnd); int credis_flushdb(REDIS rhnd);
int credis_flushall(REDIS rhnd); int credis_flushall(REDIS rhnd);
/* /*
* Commands operating on string values * Commands operating on string values
*/ */
int credis_set(REDIS rhnd, const char *key, const char *val); int credis_set(REDIS rhnd, const char *key, const char *val);
int credis_setex(REDIS rhnd, const char *key, const char *val, int seconds)
;
/* returns -1 if the key doesn't exists */ /* returns -1 if the key doesn't exists */
int credis_get(REDIS rhnd, const char *key, char **val); int credis_get(REDIS rhnd, const char *key, char **val);
/* returns -1 if the key doesn't exists */ /* returns -1 if the key doesn't exists */
int credis_getset(REDIS rhnd, const char *key, const char *set_val, char ** get_val); int credis_getset(REDIS rhnd, const char *key, const char *set_val, char ** get_val);
/* returns number of values returned in vector `valv'. `keyc' is the number of /* returns number of values returned in vector `valv'. `keyc' is the number of
* keys stored in `keyv'. */ * keys stored in `keyv'. */
int credis_mget(REDIS rhnd, int keyc, const char **keyv, char ***valv); int credis_mget(REDIS rhnd, int keyc, const char **keyv, char ***valv);
/* returns -1 if the key already exists and hence not set */ /* returns -1 if the key already exists and hence not set */
int credis_setnx(REDIS rhnd, const char *key, const char *val); int credis_setnx(REDIS rhnd, const char *key, const char *val);
/* TODO /* TODO
* SETEX key time value Set+Expire combo command
* MSET key1 value1 key2 value2 ... keyN valueN set a multiple keys to mult iple values in a single atomic operation * MSET key1 value1 key2 value2 ... keyN valueN set a multiple keys to mult iple values in a single atomic operation
* MSETNX key1 value1 key2 value2 ... keyN valueN set a multiple keys to mu ltiple values in a single atomic operation if none of * MSETNX key1 value1 key2 value2 ... keyN valueN set a multiple keys to mu ltiple values in a single atomic operation if none of
*/ */
/* if `new_val' is not NULL it will return the value after the increment wa s performed */ /* if `new_val' is not NULL it will return the value after the increment wa s performed */
int credis_incr(REDIS rhnd, const char *key, int *new_val); int credis_incr(REDIS rhnd, const char *key, int *new_val);
/* if `new_val' is not NULL it will return the value after the increment wa s performed */ /* if `new_val' is not NULL it will return the value after the increment wa s performed */
int credis_incrby(REDIS rhnd, const char *key, int incr_val, int *new_val); int credis_incrby(REDIS rhnd, const char *key, int incr_val, int *new_val);
skipping to change at line 249 skipping to change at line 255
int credis_decr(REDIS rhnd, const char *key, int *new_val); int credis_decr(REDIS rhnd, const char *key, int *new_val);
/* if `new_val' is not NULL it will return the value after the decrement wa s performed */ /* if `new_val' is not NULL it will return the value after the decrement wa s performed */
int credis_decrby(REDIS rhnd, const char *key, int decr_val, int *new_val); int credis_decrby(REDIS rhnd, const char *key, int decr_val, int *new_val);
/* returns new length of string after `val' has been appended */ /* returns new length of string after `val' has been appended */
int credis_append(REDIS rhnd, const char *key, const char *val); int credis_append(REDIS rhnd, const char *key, const char *val);
int credis_substr(REDIS rhnd, const char *key, int start, int end, char **s ubstr); int credis_substr(REDIS rhnd, const char *key, int start, int end, char **s ubstr);
/* is an alias for credis_substr(), the command SUBSTR was renamed to GETRA
NGE in Redis > 2.0
* but is automatically handled by credis */
int credis_getrange(REDIS rhnd, const char *key, int start, int end, char *
*substr);
/* /*
* Commands operating on lists * Commands operating on lists
*/ */
/* if Redis server version is 2.0 or later the number of elements inside th
e list
* after the push operation is returned on success */
int credis_rpush(REDIS rhnd, const char *key, const char *element); int credis_rpush(REDIS rhnd, const char *key, const char *element);
/* if Redis server version is 2.0 or later the number of elements inside th
e list
* after the push operation is returned on success */
int credis_lpush(REDIS rhnd, const char *key, const char *element); int credis_lpush(REDIS rhnd, const char *key, const char *element);
/* returns length of list */ /* returns length of list */
int credis_llen(REDIS rhnd, const char *key); int credis_llen(REDIS rhnd, const char *key);
/* returns number of elements returned in vector `elementv' */ /* returns number of elements returned in vector `elementv' */
int credis_lrange(REDIS rhnd, const char *key, int start, int range, char * **elementv); int credis_lrange(REDIS rhnd, const char *key, int start, int range, char * **elementv);
int credis_ltrim(REDIS rhnd, const char *key, int start, int end); int credis_ltrim(REDIS rhnd, const char *key, int start, int end);
skipping to change at line 347 skipping to change at line 361
* Commands operating on sorted sets * Commands operating on sorted sets
*/ */
/* returns -1 if member was already a member of the sorted set and only sco re was updated, /* returns -1 if member was already a member of the sorted set and only sco re was updated,
* 0 is returned if the new element was added */ * 0 is returned if the new element was added */
int credis_zadd(REDIS rhnd, const char *key, double score, const char *memb er); int credis_zadd(REDIS rhnd, const char *key, double score, const char *memb er);
/* returns -1 if the member was not a member of the sorted set */ /* returns -1 if the member was not a member of the sorted set */
int credis_zrem(REDIS rhnd, const char *key, const char *member); int credis_zrem(REDIS rhnd, const char *key, const char *member);
/* returns -1 if the member was not a member of the sorted set, the score o /* the score of the member after the increment by `incr_score' is returned
f the member after by `new_score' */
* the increment by `incr_score' is returned by `new_score' */
int credis_zincrby(REDIS rhnd, const char *key, double incr_score, const ch ar *member, double *new_score); int credis_zincrby(REDIS rhnd, const char *key, double incr_score, const ch ar *member, double *new_score);
/* returns the rank of the given member or -1 if the member was not a membe r of the sorted set */ /* returns the rank of the given member or -1 if the member was not a membe r of the sorted set */
int credis_zrank(REDIS rhnd, const char *key, const char *member); int credis_zrank(REDIS rhnd, const char *key, const char *member);
/* returns the reverse rank of the given member or -1 if the member was not a member of the sorted set */ /* returns the reverse rank of the given member or -1 if the member was not a member of the sorted set */
int credis_zrevrank(REDIS rhnd, const char *key, const char *member); int credis_zrevrank(REDIS rhnd, const char *key, const char *member);
/* returns number of elements returned in vector `elementv' /* returns number of elements returned in vector `elementv'
* TODO add support for WITHSCORES */ * TODO add support for WITHSCORES */
int credis_zrange(REDIS rhnd, const char *key, int start, int end, char *** elementv); int credis_zrange(REDIS rhnd, const char *key, int start, int end, char *** elementv);
/* returns number of elements returned in vector `elementv' /* returns number of elements returned in vector `elementv'
* TODO add support for LIMIT
* TODO add support for WITHSCORES */
int credis_zrangebyscore(REDIS rhnd, const char *key, double min, double ma
x, char ***elementv);
/* returns number of elements returned in vector `elementv'
* TODO add support for LIMIT
* TODO add support for WITHSCORES */
int credis_zrevrangebyscore(REDIS rhnd, const char *key, double max, double
min, char ***elementv);
/* returns number of elements returned in vector `elementv'
* TODO add support for WITHSCORES */ * TODO add support for WITHSCORES */
int credis_zrevrange(REDIS rhnd, const char *key, int start, int end, char ***elementv); int credis_zrevrange(REDIS rhnd, const char *key, int start, int end, char ***elementv);
/* returns cardinality or -1 if `key' does not exist */ /* returns cardinality or -1 if `key' does not exist */
int credis_zcard(REDIS rhnd, const char *key); int credis_zcard(REDIS rhnd, const char *key);
/* returns -1 if the `key' does not exist or the `member' is not in the sor ted set, /* returns -1 if the `key' does not exist or the `member' is not in the sor ted set,
* score is returned in `score' */ * score is returned in `score' */
int credis_zscore(REDIS rhnd, const char *key, const char *member, double * score); int credis_zscore(REDIS rhnd, const char *key, const char *member, double * score);
/* returns number of elements removed or -1 if key does not exist */ /* returns number of elements removed or -1 if key does not exist */
int credis_zremrangebyscore(REDIS rhnd, const char *key, double min, double max); int credis_zremrangebyscore(REDIS rhnd, const char *key, double min, double max);
/* returns number of elements removed or -1 if key does not exist */ /* returns number of elements removed or -1 if key does not exist */
int credis_zremrangebyrank(REDIS rhnd, const char *key, int start, int end) ; int credis_zremrangebyrank(REDIS rhnd, const char *key, int start, int end) ;
/* TODO
* ZRANGEBYSCORE key min max Return all the elements with score >= min and
score <= max (a range query) from the sorted set
*/
/* `keyc' is the number of keys stored in `keyv'. `weightv' is optional, if not /* `keyc' is the number of keys stored in `keyv'. `weightv' is optional, if not
* NULL, `keyc' is also the number of weights stored in `weightv'. */ * NULL, `keyc' is also the number of weights stored in `weightv'. */
int credis_zinterstore(REDIS rhnd, const char *destkey, int keyc, const cha r **keyv, int credis_zinterstore(REDIS rhnd, const char *destkey, int keyc, const cha r **keyv,
const int *weightv, REDIS_AGGREGATE aggregate); const int *weightv, REDIS_AGGREGATE aggregate);
/* `keyc' is the number of keys stored in `keyv'. `weightv' is optional, if not /* `keyc' is the number of keys stored in `keyv'. `weightv' is optional, if not
* NULL, `keyc' is also the number of weights stored in `weightv'. */ * NULL, `keyc' is also the number of weights stored in `weightv'. */
int credis_zunionstore(REDIS rhnd, const char *destkey, int keyc, const cha r **keyv, int credis_zunionstore(REDIS rhnd, const char *destkey, int keyc, const cha r **keyv,
const int *weightv, REDIS_AGGREGATE aggregate); const int *weightv, REDIS_AGGREGATE aggregate);
/* /*
* Commands operating on hashes * Commands operating on hashes
*/ */
/* 1 is returned if the field already exists and its value is updated, 0 is
* returned if the field is created */
int credis_hset(REDIS rhnd, const char *key, const char *field, const char
*value);
/* returns -1 if key or field don't exist */
int credis_hget(REDIS rhnd, const char *key, const char *field, char **valu
e);
/* returns number of field names returned in vector `fieldv'. 0 is returned
if `key'
* is empty or does not exist */
int credis_hkeys(REDIS rhnd, const char *key, char ***fieldv);
/* returns number of fields in the hash, or 0 if `key' does not exist */
int credis_hlen(REDIS rhnd, const char *key);
/* returns number of values returned in vector `valv'. `fieldc' is the numb
er
* of fields stored in `fieldv'. */
int credis_hmget(REDIS rhnd, const char *key, int fieldc, const char **fiel
dv, char ***valv);
/* TODO /* TODO
* HSET key field value Set the hash field to the specified value. Creates
the hash if needed.
* HGET key field Retrieve the value of the specified hash field.
* HMSET key field1 value1 ... fieldN valueN Set the hash fields to their r espective values. * HMSET key field1 value1 ... fieldN valueN Set the hash fields to their r espective values.
* HINCRBY key field integer Increment the integer value of the hash at _ke y_ on _field_ with _integer_. * HINCRBY key field integer Increment the integer value of the hash at _ke y_ on _field_ with _integer_.
* HEXISTS key field Test for existence of a specified field in a hash * HEXISTS key field Test for existence of a specified field in a hash
* HDEL key field Remove the specified field from a hash * HDEL key field Remove the specified field from a hash
* HLEN key Return the number of items in a hash.
* HKEYS key Return all the fields in a hash.
* HVALS key Return all the values in a hash. * HVALS key Return all the values in a hash.
* HGETALL key Return all the fields and associated values in a hash. * HGETALL key Return all the fields and associated values in a hash.
*/ */
/* /*
* Sorting * Sorting
*/ */
/* returns number of elements returned in vector `elementv' */ /* returns number of elements returned in vector `elementv' */
int credis_sort(REDIS rhnd, const char *query, char ***elementv); int credis_sort(REDIS rhnd, const char *query, char ***elementv);
skipping to change at line 426 skipping to change at line 459
/* /*
* Transactions * Transactions
*/ */
/* TODO /* TODO
* MULTI/EXEC/DISCARD Redis atomic transactions * MULTI/EXEC/DISCARD Redis atomic transactions
*/ */
/* /*
* Publish/Subscribe * Publish/Subscribe
*/ *
* !!EXPERIMENTAL!! Expect API and implementation to change until these
* lines are removed.
*
* The nature of the publish/subscribe messaging paradigm differs from the
* rest of Redis, the main difference being messages are pushed to subscrib
ing
* clients. Credis tries to hide some of this de-coupling in order to make
life
* easier for application programmers. All subscribe, unsubscribe and publi
sh
* function calls will return when an acknowledgement has been received or
on
* error (including timeout), just as all other Credis function calls that
map
* to Redis commands. If a message is pushed to the client while waiting fo
r
* an acknowledgement, to for instance a new subscription, that message is
* stored on an internal FIFO. When the client is ready to receive messages
a
* call to listen function is made and if there is a message in the FIFO it
is
* immediately returned else Credis waits for a message being pushed from R
edis.
*
* IMPORTANT! Note that while subscribing to one or more channels (or patte
rns)
* the client is in a publish/subscribe state in which is not allowed to pe
rform
* other commands.
*/
/* On success the number of channels we are currently subscribed to is
* returned. */
int credis_subscribe(REDIS rhnd, const char *channel);
/* `channel' specifies the channel to unsubscribe from. If set to NULL
* all channels are unsubscribed from. On success the number of channels
* we are currently subscribed to is returned. */
int credis_unsubscribe(REDIS rhnd, const char *channel);
/* On success the number of channels we are currently subscribed to is
* returned. */
int credis_psubscribe(REDIS rhnd, const char *pattern);
/* `pattern' specifies the channels to unsubscribe from. If set to NULL
* all are unsubscribed from. On success the number of channels we are
* currently subscribed to is returned. */
int credis_punsubscribe(REDIS rhnd, const char *pattern);
/* TODO /* On success the number of clients that received the message is returned *
* SUBSCRIBE/UNSUBSCRIBE/PUBLISH Redis Public/Subscribe messaging paradigm /
implementation int credis_publish(REDIS rhnd, const char *channel, const char *message);
*/
/* Listen for messages from channels and/or patterns subscribed to */
int credis_listen(REDIS rhnd, char **pattern, char **channel, char **messag
e);
/* /*
* Persistence control commands * Persistence control commands
*/ */
int credis_save(REDIS rhnd); int credis_save(REDIS rhnd);
int credis_bgsave(REDIS rhnd); int credis_bgsave(REDIS rhnd);
/* returns UNIX time stamp of last successfull save to disk */ /* returns UNIX time stamp of last successfull save to disk */
 End of changes. 18 change blocks. 
21 lines changed or deleted 115 lines changed or added

This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/