Hiredis SMEMBERS 활용

Programming/Redis 2017. 1. 24. 13:34 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Hiredis SMEMBERS 활용








	redisReply *reply;
	redisAppendCommand(context, "SMEMBERS myset");
	redisGetReply(context, (void**)&reply);
	for (int i = 0; i < reply->elements; i++)
	{
		// reply->element[i]->str; // myset
	}

	freeReplyObject(reply);












참고 : https://redis.io/commands/smembers

참고 : https://github.com/redis/hiredis/blob/master/examples/example.c



'Programming > Redis' 카테고리의 다른 글

Redis Client Connect Test  (0) 2016.10.26
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28

Redis Client Connect Test

Programming/Redis 2016. 10. 26. 11:52 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Redis Client Connect Test





CLIENT LIST

The CLIENT LIST command returns information and statistics about the client connections server in a mostly human readable format.

Return value

Bulk string reply: a unique string, formatted as follows:

  • One client connection per line (separated by LF)
  • Each line is composed of a succession of property=value fields separated by a space character.

Here is the meaning of the fields:

  • id: an unique 64-bit client ID (introduced in Redis 2.8.12).
  • addr: address/port of the client
  • fd: file descriptor corresponding to the socket
  • age: total duration of the connection in seconds
  • idle: idle time of the connection in seconds
  • flags: client flags (see below)
  • db: current database ID
  • sub: number of channel subscriptions
  • psub: number of pattern matching subscriptions
  • multi: number of commands in a MULTI/EXEC context
  • qbuf: query buffer length (0 means no query pending)
  • qbuf-free: free space of the query buffer (0 means the buffer is full)
  • obl: output buffer length
  • oll: output list length (replies are queued in this list when the buffer is full)
  • omem: output buffer memory usage
  • events: file descriptor events (see below)
  • cmd: last command played

The client flags can be a combination of:

O: the client is a slave in MONITOR mode
S: the client is a normal slave server
M: the client is a master
x: the client is in a MULTI/EXEC context
b: the client is waiting in a blocking operation
i: the client is waiting for a VM I/O (deprecated)
d: a watched keys has been modified - EXEC will fail
c: connection to be closed after writing entire reply
u: the client is unblocked
U: the client is connected via a Unix domain socket
r: the client is in readonly mode against a cluster node
A: connection to be closed ASAP
N: no specific flag set

The file descriptor events can be:

r: the client socket is readable (event loop)
w: the client socket is writable (event loop)


'Programming > Redis' 카테고리의 다른 글

Hiredis SMEMBERS 활용  (0) 2017.01.24
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28

Hiredis Subscribe/Publish with CWinThread

Programming/Redis 2016. 10. 5. 14:01 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Hiredis Subscribe/Publish



CWinThread 를 이용한 구현




struct event_base *base = event_base_new();

class CRedisConnect : public CWinThread
{
public:
	redisAsyncContext *c;
	// CWinThread extends
	virtual BOOL InitInstance();
	virtual int Run();
};

BOOL CRedisConnect::InitInstance()
{
	return TRUE;
}

int CRedisConnect::Run()
{
	c = redisAsyncConnect(redisServerIP, redisServerPort);
	if (c->err) {
		/* Let *c leak for now... */
		return 1;
	}
	redisLibeventAttach(c, base);

	int re2 = redisAsyncCommand(c, getCallback, NULL, "SUBSCRIBE foo");

	event_base_dispatch(base);

	return (0);
}



void getCallback(redisAsyncContext *c, void *r, void *privdata) {

	redisReply *reply = (redisReply *)r;
	if (reply == NULL)
	{
		LOG4CXX_DEBUG(g_log, "Subcribe reply == NULL");
	}
	// reply->type
	// #define REDIS_REPLY_STRING 1
	// #define REDIS_REPLY_ARRAY 2
	// #define REDIS_REPLY_INTEGER 3
	// #define REDIS_REPLY_NIL 4
	// #define REDIS_REPLY_STATUS 5
	// #define REDIS_REPLY_ERROR 6
	else if (reply->type == REDIS_REPLY_ERROR)
	{
		LOG4CXX_DEBUG(g_log, "Subcribe reply type == REDIS_REPLY_ERROR");
	}
	else if (reply->type == REDIS_REPLY_ARRAY)
	{
		LOG4CXX_DEBUG(g_log, "reply->elements == " << reply->elements);
		LOG4CXX_DEBUG(g_log, "reply->len == " << reply->len);
		for (int i = 0; i < reply->elements; i++)
		{
			if (reply->element[i]->str != NULL)
			LOG4CXX_DEBUG(g_log, "Subcribe reply array [" << i << "] == " << reply->element[i]->str);			
		}		
	}
	else
	{
		LOG4CXX_DEBUG(g_log, "getCallback reply str : " << reply->str);
	}
}

'Programming > Redis' 카테고리의 다른 글

Hiredis SMEMBERS 활용  (0) 2017.01.24
Redis Client Connect Test  (0) 2016.10.26
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28

How to use Pub/sub with hiredis in C++?

Programming/Redis 2016. 9. 29. 14:06 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

example for pub/sub



https://github.com/redis/hiredis/issues/55 aluiken commented on Mar 2, 2012




void onMessage(redisAsyncContext *c, void *reply, void *privdata) {
    redisReply *r = reply;
    if (reply == NULL) return;

    if (r->type == REDIS_REPLY_ARRAY) {
        for (int j = 0; j < r->elements; j++) {
            printf("%u) %s\n", j, r->element[j]->str);
        }
    }
}

int main (int argc, char **argv) {
    signal(SIGPIPE, SIG_IGN);
    struct event_base *base = event_base_new();

    redisAsyncContext *c = redisAsyncConnect("127.0.0.1", 6379);
    if (c->err) {
        printf("error: %s\n", c->errstr);
        return 1;
    }

    redisLibeventAttach(c, base);
    redisAsyncCommand(c, onMessage, NULL, "SUBSCRIBE testtopic");
    event_base_dispatch(base);
    return 0;
}

'Programming > Redis' 카테고리의 다른 글

Redis Client Connect Test  (0) 2016.10.26
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28
Windows7 Redis 설치 및 실행  (0) 2016.09.27

hiredis fatal error C1853:

Programming/Redis 2016. 9. 29. 09:03 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

hiredis fatal error C1853:






hiredis\async.c : fatal error C1853: 'x64\Release\--------------.pch' 미리 컴파일된 헤더 파일이 이전 버전의 컴파일러에서 만들어졌거나, 미리 컴파일된 헤더가 C++인데 C에서 사용하고 있거나 또는 그 반대의 경우입니다.

hiredis\dict.c : fatal error C1853: 'x64\Release\--------------.pch' 미리 컴파일된 헤더 파일이 이전 버전의 컴파일러에서 만들어졌거나, 미리 컴파일된 헤더가 C++인데 C에서 사용하고 있거나 또는 그 반대의 경우입니다.

hiredis\hiredis.c : fatal error C1853: 'x64\Release\--------------.pch' 미리 컴파일된 헤더 파일이 이전 버전의 컴파일러에서 만들어졌거나, 미리 컴파일된 헤더가 C++인데 C에서 사용하고 있거나 또는 그 반대의 경우입니다.

hiredis\net.c : fatal error C1853: 'x64\Release\--------------.pch' 미리 컴파일된 헤더 파일이 이전 버전의 컴파일러에서 만들어졌거나, 미리 컴파일된 헤더가 C++인데 C에서 사용하고 있거나 또는 그 반대의 경우입니다.

hiredis\sds.c : fatal error C1853: 'x64\Release\--------------.pch' 미리 컴파일된 헤더 파일이 이전 버전의 컴파일러에서 만들어졌거나, 미리 컴파일된 헤더가 C++인데 C에서 사용하고 있거나 또는 그 반대의 경우입니다.





 미리 컴파일된 헤더














'Programming > Redis' 카테고리의 다른 글

Redis Client Connect Test  (0) 2016.10.26
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28
Windows7 Redis 설치 및 실행  (0) 2016.09.27

hiredis MFC import Visual Studio 2013

Programming/Redis 2016. 9. 28. 11:49 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

hiredis MFC import




Hiredis is a minimalistic C client library for the Redis database.

It is minimalistic because it just adds minimal support for the protocol, but at the same time it uses a high level printf-alike API in order to make it much higher level than otherwise suggested by its minimal code base and the lack of explicit bindings for every Redis command.


1. Download Hiredis

Project Site : https://github.com/redis/hiredis


[Clone or download] [Download ZIP]




2. Include Hiredis Header Files



3. Config Hiredis Header Files Path







4. Build Hiredis Library File


Open Hiredis Project





Build Hiredis Project





5. Config Hiredis Library File Path





6. Sample Code




#include 
#include 
#include 

#include "hiredis.h"

#ifdef HIREDIS_WIN
#define snprintf sprintf_s
#endif

int main(void) {
    unsigned int j;
    redisContext *c;
    redisReply *reply;

    struct timeval timeout = { 1, 500000 }; // 1.5 seconds
    c = redisConnectWithTimeout((char*)"127.0.0.1", 6379, timeout);
    if (c->err) {
        printf("Connection error: %s\n", c->errstr);
        exit(1);
    }

    /* PING server */
    reply = redisCommand(c,"PING");
    printf("PING: %s\n", reply->str);
    freeReplyObject(reply);

    /* Set a key */
    reply = redisCommand(c,"SET %s %s", "foo", "hello world");
    printf("SET: %s\n", reply->str);
    freeReplyObject(reply);

    /* Set a key using binary safe API */
    reply = redisCommand(c,"SET %b %b", "bar", 3, "hello", 5);
    printf("SET (binary API): %s\n", reply->str);
    freeReplyObject(reply);

    /* Try a GET and two INCR */
    reply = redisCommand(c,"GET foo");
    printf("GET foo: %s\n", reply->str);
    freeReplyObject(reply);

    reply = redisCommand(c,"INCR counter");
    printf("INCR counter: %lld\n", reply->integer);
    freeReplyObject(reply);
    /* again ... */
    reply = redisCommand(c,"INCR counter");
    printf("INCR counter: %lld\n", reply->integer);
    freeReplyObject(reply);

    /* Create a list of numbers, from 0 to 9 */
    reply = redisCommand(c,"DEL mylist");
    freeReplyObject(reply);
    for (j = 0; j < 10; j++) {
        char buf[64];

        snprintf(buf,64,"%d",j);
        reply = redisCommand(c,"LPUSH mylist element-%s", buf);
        freeReplyObject(reply);
    }

    /* Let's check what we have inside the list */
    reply = redisCommand(c,"LRANGE mylist 0 -1");
    if (reply->type == REDIS_REPLY_ARRAY) {
        for (j = 0; j < reply->elements; j++) {
            printf("%u) %s\n", j, reply->element[j]->str);
        }
    }
    freeReplyObject(reply);

    return 0;
}


7. Sample Monitor






'Programming > Redis' 카테고리의 다른 글

Redis Client Connect Test  (0) 2016.10.26
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
Windows7 Redis 설치 및 실행  (0) 2016.09.27

Windows7 Redis 설치 및 실행

Programming/Redis 2016. 9. 27. 14:21 Posted by TanSanC
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Redis


Redis is an open source (BSD licensed), in-memory data structure store, used as database, cache and message broker. It supports data structures such as stringshasheslistssets,sorted sets with range queries, bitmapshyperloglogs and geospatial indexes with radius queries. Redis has built-in replicationLua scriptingLRU evictiontransactions and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.



1. Windows 용 redis


https://github.com/dmajkic/redis/downloads





2. execute redis-server.exe



3. execute redis-cli.exe




'Programming > Redis' 카테고리의 다른 글

Redis Client Connect Test  (0) 2016.10.26
Hiredis Subscribe/Publish with CWinThread  (0) 2016.10.05
How to use Pub/sub with hiredis in C++?  (0) 2016.09.29
hiredis fatal error C1853:  (0) 2016.09.29
hiredis MFC import Visual Studio 2013  (0) 2016.09.28