84#include <hiredis/hiredis.h>
89static Value hiredis_reply_to_value(
const redisReply *r);
98typedef struct RedisHandle {
101 struct RedisHandle *next;
105static RedisHandle *g_redis_handles = NULL;
107static int g_redis_next_id = 1;
121static RedisHandle *redis_reg_add(redisContext *ctx) {
122 RedisHandle *h = (RedisHandle *)calloc(1,
sizeof(RedisHandle));
124 h->id = g_redis_next_id++;
126 h->next = g_redis_handles;
142static RedisHandle *redis_reg_get(
int id) {
143 for (RedisHandle *p = g_redis_handles; p; p = p->next)
144 if (p->id ==
id)
return p;
159static void redis_reg_del(
int id) {
160 RedisHandle **pp = &g_redis_handles;
162 if ((*pp)->id ==
id) {
163 RedisHandle *d = *pp;
186static Value hiredis_reply_to_value(
const redisReply *r) {
189 case REDIS_REPLY_STRING:
190 case REDIS_REPLY_STATUS:
192 case REDIS_REPLY_INTEGER:
193 return make_int((int64_t)r->integer);
194 case REDIS_REPLY_NIL:
196 case REDIS_REPLY_ARRAY: {
197 int n = (int)r->elements;
203 for (
int i = 0; i < n; i++) {
204 items[i] = hiredis_reply_to_value(r->element[i]);
207 for (
int i = 0; i < n; i++)
free_value(items[i]);
211#ifdef REDIS_REPLY_DOUBLE
212 case REDIS_REPLY_DOUBLE:
215 case REDIS_REPLY_ERROR:
Tagged union representing a Fun value.
Value make_nil(void)
Construct a nil Value.
Value make_string(const char *s)
Construct a string Value by duplicating the given C string.
void free_value(Value v)
Free dynamic storage owned by a Value.
Value make_float(double v)
Construct a Value representing a double-precision float.
Value make_int(int64_t v)
Construct a Value representing a 64-bit integer.
Value make_array_from_values(const Value *vals, int count)
Create an array Value by copying items from an input span.