gosexy / redis Goto Github PK
View Code? Open in Web Editor NEWRedis client for Go that maps the full redis command list into equivalent Go functions.
License: MIT License
Redis client for Go that maps the full redis command list into equivalent Go functions.
License: MIT License
There is a race condition with go1.1.2 and redis-server 2.6.16.
Sometimes go test
hungs or fails with a SIGSEGV. Session log below.
SIGSEGV: segmentation violation
PC=0x1000
signal arrived during cgo execution
menteslibres.net/gosexy/redis._Cfunc_redisGoroutineReadEvent(0x7fd4dc000990)
menteslibres.net/gosexy/redis/_test/_cgo_defun.c:187 +0x2f
menteslibres.net/gosexy/redis.func·002()
menteslibres.net/gosexy/redis/_test/_cgo_gotypes.go:418 +0x27
menteslibres.net/gosexy/redis.(*pollServer).Run(0xc2000840e0)
/home/reventlov/go/src/menteslibres.net/gosexy/redis/fd.go:123 +0x1ea
created by menteslibres.net/gosexy/redis.newPollServer
/home/reventlov/go/src/menteslibres.net/gosexy/redis/newpollserver.go:31 +0xcf
goroutine 1 [chan receive]:
testing.RunTests(0x589868, 0x83d540, 0x1e, 0x1e, 0x43ac01, ...)
/usr/local/go/src/pkg/testing/testing.go:434 +0x88e
testing.Main(0x589868, 0x83d540, 0x1e, 0x1e, 0x83b6a0, ...)
/usr/local/go/src/pkg/testing/testing.go:365 +0x8a
main.main()
menteslibres.net/gosexy/redis/_test/_testmain.go:117 +0x9a
goroutine 2 [syscall]:
goroutine 22 [syscall]:
menteslibres.net/gosexy/redis._Cfunc_redisConnectNonBlock(0x7fd4dc0008c0, 0x18eb, 0x7fd4dc0008c0)
menteslibres.net/gosexy/redis/_test/_cgo_defun.c:115 +0x2f
menteslibres.net/gosexy/redis.(*Client).ConnectNonBlock(0xc2000b8c20, 0x55cbd0, 0x4, 0x5065e0, 0xc2000ade00, ...)
menteslibres.net/gosexy/redis/_test/_cgo_gotypes.go:537 +0x4d
menteslibres.net/gosexy/redis.TestPSubscriptions(0xc20008cd80)
/home/reventlov/go/src/menteslibres.net/gosexy/redis/main_test.go:1095 +0x8a
testing.tRunner(0xc20008cd80, 0x83d6c0)
/usr/local/go/src/pkg/testing/testing.go:353 +0x8a
created by testing.RunTests
/usr/local/go/src/pkg/testing/testing.go:433 +0x86b
rax 0x1000
rbx 0x7fd4dc000d30
rcx 0x7fd4d8000028
rdx 0x7fd4fa5ed060
rdi 0x7fd4dc000d30
rsi 0x7fd4d80008e0
rbp 0x7fd4dc000e28
rsp 0x7fd4e95d7d48
r8 0x0
r9 0x3a
r10 0x50
r11 0x7fd4f9f71f80
r12 0x7fd4dc000c10
r13 0x7fd4d8000aa8
r14 0x7fd4d8000a40
r15 0x7fd4d80008e0
rip 0x1000
rflags 0x10206
cs 0x33
fs 0x0
gs 0x0
exit status 2
FAIL menteslibres.net/gosexy/redis 0.057s
Code:
v, err := r.BLPop(5, "A", "B", "C")
Results in MONITOR
via redis-cli:
1379287885.511023 [0 127.0.0.1:36286] "BLPOP" "5" "B" "C" ""
This code results in the error:
self.redis.Multi()
for i := 1; i <= max; i++ {
s := compact[:i]
self.redis.ZAdd("keywordlookup", 0, s)
}
self.redis.ZInterStore("keywordmatch", 2, "keywordlookup", route)
self.redis.ZRevRange("keywordmatch", 0, 0)
res, err = self.redis.Exec()
If I execute the ZRevRange after the Exec everything is fine.
This is with the Master branch
Currently to make use of the INFO command you have to parse the resulting string. Bindings for redis clients in other languages tend to use the info command as an opportunity to return, for example, a map of the results. This makes using the info command simple, and improves the usability of the library.
It would be better if the info command did the same. Since Go (afaik) doesn't allow maps with different value types a struct could be returned. This would provide the caller with directly usable info results lowering the curve for using this library.
The downside would likely be the need to update the struct construction when new fields and sections are added. However, once the base code for doing the conversion is done (I'm still new to go) I'd be happy to do that maintenance when those changes occur.
Hi, don't know if this is a problem related to my crappy code, these go-bindings, hiredis or redis:
When calling a lot of redis commands, maybe a few thousand a second, through a single connection I get this strange error: Protocol error: too big inline request
.
While trying to debug this i find that the error is being raised in redis when the queue(?) goes too big or at least exceeds a constant named REDIS_INLINE_MAX_SIZE
: https://github.com/antirez/redis/blob/unstable/src/networking.c#L892-L900
is this something i should be thinking about? not throwing too much at redis? would multiple connections do better? THANKS!
只看文档,不知所云
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go install qiutask
src/github.com/gosexy/redis/fd.go:121: undefined: fdev
src/github.com/gosexy/redis/fd.go:122: undefined: fdev
Hi,
How to execute fuzzy matching by gosexy redis?
like:
business_info = client.get("business_*")
I hope it return all key=>values that key starts by "business_"
The Redis documentation specifies that when executing ordinary commands in the Multi mode, the string QUEUED
or an error, if any, is returned. Despite this, there is sometimes a need to check for errors in this mode, but this is not possible due to panic like this:
Unsupported conversion: status to int64
Unsupported conversion: status to slice
Unsupported conversion: status to bool
run example, gofmt report a error:
expected declaration, found 'IDENT' client
var client *redis.Client
client = redis.New() <--error point to this line
it must in a func. not bug
Can you provide an example for get/set golang struct?
HI,
I installed hiredis, and I have this bug:
$ go get -u menteslibres.net/gosexy/redis
# menteslibres.net/gosexy/redis
cc did not produce error at completed:1
on input:
#line 31 "/home/loic/gocode/src/menteslibres.net/gosexy/redis/main.go"
#include <stdarg.h>
#include <stdlib.h>
#include "net.h"
#include "sds.h"
#include "hiredis.h"
#include "async.h"
typedef struct redisEvent {
} redisEvent;
// Redis events with goroutines.
typedef struct redisGoroutineEvents {
redisAsyncContext *context;
} redisGoroutineEvents;
int redisGetReplyType(redisReply *);
struct timeval redisTimeVal(long, long);
void getCallback(redisAsyncContext *, void *, void *);
int redisGetReplyType(redisReply *);
int redisAsyncCommandArgvWrapper(redisAsyncContext *, void *, int, const char **, const size_t *);
redisReply *redisReplyGetElement(redisReply *, int i);
int redisGoroutineAttach(redisAsyncContext *, redisEvent *);
void redisGoroutineWriteEvent(void *);
void redisGoroutineReadEvent(void *);
void redisForceAsyncFree(redisAsyncContext *);
void redisAsyncSetCallbacks(redisAsyncContext *);
#include <sys/types.h> /* for size_t below */
/* Define intgo when compiling with GCC. */
#ifdef __PTRDIFF_TYPE__
typedef __PTRDIFF_TYPE__ intgo;
#elif defined(_LP64)
typedef long long intgo;
#else
typedef int intgo;
#endif
typedef struct { char *p; intgo n; } _GoString_;
typedef struct { char *p; intgo n; intgo c; } _GoBytes_;
_GoString_ GoString(char *p);
_GoString_ GoStringN(char *p, int l);
_GoBytes_ GoBytes(void *p, int n);
char *CString(_GoString_);
void *_CMalloc(size_t);
#line 1 "not-declared"
void __cgo_f_1_1(void) { __typeof__(freeReplyObject) *__cgo_undefined__; }
#line 1 "not-type"
void __cgo_f_1_2(void) { freeReplyObject *__cgo_undefined__; }
#line 1 "not-const"
void __cgo_f_1_3(void) { enum { __cgo__undefined__ = (freeReplyObject)*1 }; }
#line 2 "not-declared"
void __cgo_f_2_1(void) { __typeof__(redisFree) *__cgo_undefined__; }
#line 2 "not-type"
void __cgo_f_2_2(void) { redisFree *__cgo_undefined__; }
#line 2 "not-const"
void __cgo_f_2_3(void) { enum { __cgo__undefined__ = (redisFree)*1 }; }
#line 3 "not-declared"
void __cgo_f_3_1(void) { __typeof__(redisAsyncInitialize) *__cgo_undefined__; }
#line 3 "not-type"
void __cgo_f_3_2(void) { redisAsyncInitialize *__cgo_undefined__; }
#line 3 "not-const"
void __cgo_f_3_3(void) { enum { __cgo__undefined__ = (redisAsyncInitialize)*1 }; }
#line 4 "not-declared"
void __cgo_f_4_1(void) { __typeof__(GoString) *__cgo_undefined__; }
#line 4 "not-type"
void __cgo_f_4_2(void) { GoString *__cgo_undefined__; }
#line 4 "not-const"
void __cgo_f_4_3(void) { enum { __cgo__undefined__ = (GoString)*1 }; }
#line 5 "not-declared"
void __cgo_f_5_1(void) { __typeof__(redisAsyncCommandArgvWrapper) *__cgo_undefined__; }
#line 5 "not-type"
void __cgo_f_5_2(void) { redisAsyncCommandArgvWrapper *__cgo_undefined__; }
#line 5 "not-const"
void __cgo_f_5_3(void) { enum { __cgo__undefined__ = (redisAsyncCommandArgvWrapper)*1 }; }
#line 6 "not-declared"
void __cgo_f_6_1(void) { __typeof__(size_t) *__cgo_undefined__; }
#line 6 "not-type"
void __cgo_f_6_2(void) { size_t *__cgo_undefined__; }
#line 6 "not-const"
void __cgo_f_6_3(void) { enum { __cgo__undefined__ = (size_t)*1 }; }
#line 7 "not-declared"
void __cgo_f_7_1(void) { __typeof__(redisAsyncContext) *__cgo_undefined__; }
#line 7 "not-type"
void __cgo_f_7_2(void) { redisAsyncContext *__cgo_undefined__; }
#line 7 "not-const"
void __cgo_f_7_3(void) { enum { __cgo__undefined__ = (redisAsyncContext)*1 }; }
#line 8 "not-declared"
void __cgo_f_8_1(void) { __typeof__(redisContext) *__cgo_undefined__; }
#line 8 "not-type"
void __cgo_f_8_2(void) { redisContext *__cgo_undefined__; }
#line 8 "not-const"
void __cgo_f_8_3(void) { enum { __cgo__undefined__ = (redisContext)*1 }; }
#line 9 "not-declared"
void __cgo_f_9_1(void) { __typeof__(redisGoroutineEvents) *__cgo_undefined__; }
#line 9 "not-type"
void __cgo_f_9_2(void) { redisGoroutineEvents *__cgo_undefined__; }
#line 9 "not-const"
void __cgo_f_9_3(void) { enum { __cgo__undefined__ = (redisGoroutineEvents)*1 }; }
#line 10 "not-declared"
void __cgo_f_10_1(void) { __typeof__(redisGoroutineWriteEvent) *__cgo_undefined__; }
#line 10 "not-type"
void __cgo_f_10_2(void) { redisGoroutineWriteEvent *__cgo_undefined__; }
#line 10 "not-const"
void __cgo_f_10_3(void) { enum { __cgo__undefined__ = (redisGoroutineWriteEvent)*1 }; }
#line 11 "not-declared"
void __cgo_f_11_1(void) { __typeof__(CString) *__cgo_undefined__; }
#line 11 "not-type"
void __cgo_f_11_2(void) { CString *__cgo_undefined__; }
#line 11 "not-const"
void __cgo_f_11_3(void) { enum { __cgo__undefined__ = (CString)*1 }; }
#line 12 "not-declared"
void __cgo_f_12_1(void) { __typeof__(redisConnectUnixWithTimeout) *__cgo_undefined__; }
#line 12 "not-type"
void __cgo_f_12_2(void) { redisConnectUnixWithTimeout *__cgo_undefined__; }
#line 12 "not-const"
void __cgo_f_12_3(void) { enum { __cgo__undefined__ = (redisConnectUnixWithTimeout)*1 }; }
#line 13 "not-declared"
void __cgo_f_13_1(void) { __typeof__(redisTimeVal) *__cgo_undefined__; }
#line 13 "not-type"
void __cgo_f_13_2(void) { redisTimeVal *__cgo_undefined__; }
#line 13 "not-const"
void __cgo_f_13_3(void) { enum { __cgo__undefined__ = (redisTimeVal)*1 }; }
#line 14 "not-declared"
void __cgo_f_14_1(void) { __typeof__(redisEvent) *__cgo_undefined__; }
#line 14 "not-type"
void __cgo_f_14_2(void) { redisEvent *__cgo_undefined__; }
#line 14 "not-const"
void __cgo_f_14_3(void) { enum { __cgo__undefined__ = (redisEvent)*1 }; }
#line 15 "not-declared"
void __cgo_f_15_1(void) { __typeof__(redisConnectUnixNonBlock) *__cgo_undefined__; }
#line 15 "not-type"
void __cgo_f_15_2(void) { redisConnectUnixNonBlock *__cgo_undefined__; }
#line 15 "not-const"
void __cgo_f_15_3(void) { enum { __cgo__undefined__ = (redisConnectUnixNonBlock)*1 }; }
#line 16 "not-declared"
void __cgo_f_16_1(void) { __typeof__(GoStringN) *__cgo_undefined__; }
#line 16 "not-type"
void __cgo_f_16_2(void) { GoStringN *__cgo_undefined__; }
#line 16 "not-const"
void __cgo_f_16_3(void) { enum { __cgo__undefined__ = (GoStringN)*1 }; }
#line 17 "not-declared"
void __cgo_f_17_1(void) { __typeof__(redisReplyGetElement) *__cgo_undefined__; }
#line 17 "not-type"
void __cgo_f_17_2(void) { redisReplyGetElement *__cgo_undefined__; }
#line 17 "not-const"
void __cgo_f_17_3(void) { enum { __cgo__undefined__ = (redisReplyGetElement)*1 }; }
#line 18 "not-declared"
void __cgo_f_18_1(void) { __typeof__(redisConnectWithTimeout) *__cgo_undefined__; }
#line 18 "not-type"
void __cgo_f_18_2(void) { redisConnectWithTimeout *__cgo_undefined__; }
#line 18 "not-const"
void __cgo_f_18_3(void) { enum { __cgo__undefined__ = (redisConnectWithTimeout)*1 }; }
#line 19 "not-declared"
void __cgo_f_19_1(void) { __typeof__(char) *__cgo_undefined__; }
#line 19 "not-type"
void __cgo_f_19_2(void) { char *__cgo_undefined__; }
#line 19 "not-const"
void __cgo_f_19_3(void) { enum { __cgo__undefined__ = (char)*1 }; }
#line 20 "not-declared"
void __cgo_f_20_1(void) { __typeof__(redisGoroutineReadEvent) *__cgo_undefined__; }
#line 20 "not-type"
void __cgo_f_20_2(void) { redisGoroutineReadEvent *__cgo_undefined__; }
#line 20 "not-const"
void __cgo_f_20_3(void) { enum { __cgo__undefined__ = (redisGoroutineReadEvent)*1 }; }
#line 21 "not-declared"
void __cgo_f_21_1(void) { __typeof__(int) *__cgo_undefined__; }
#line 21 "not-type"
void __cgo_f_21_2(void) { int *__cgo_undefined__; }
#line 21 "not-const"
void __cgo_f_21_3(void) { enum { __cgo__undefined__ = (int)*1 }; }
#line 22 "not-declared"
void __cgo_f_22_1(void) { __typeof__(redisConnect) *__cgo_undefined__; }
#line 22 "not-type"
void __cgo_f_22_2(void) { redisConnect *__cgo_undefined__; }
#line 22 "not-const"
void __cgo_f_22_3(void) { enum { __cgo__undefined__ = (redisConnect)*1 }; }
#line 23 "not-declared"
void __cgo_f_23_1(void) { __typeof__(redisConnectNonBlock) *__cgo_undefined__; }
#line 23 "not-type"
void __cgo_f_23_2(void) { redisConnectNonBlock *__cgo_undefined__; }
#line 23 "not-const"
void __cgo_f_23_3(void) { enum { __cgo__undefined__ = (redisConnectNonBlock)*1 }; }
#line 24 "not-declared"
void __cgo_f_24_1(void) { __typeof__(redisForceAsyncFree) *__cgo_undefined__; }
#line 24 "not-type"
void __cgo_f_24_2(void) { redisForceAsyncFree *__cgo_undefined__; }
#line 24 "not-const"
void __cgo_f_24_3(void) { enum { __cgo__undefined__ = (redisForceAsyncFree)*1 }; }
#line 25 "not-declared"
void __cgo_f_25_1(void) { __typeof__(long) *__cgo_undefined__; }
#line 25 "not-type"
void __cgo_f_25_2(void) { long *__cgo_undefined__; }
#line 25 "not-const"
void __cgo_f_25_3(void) { enum { __cgo__undefined__ = (long)*1 }; }
#line 26 "not-declared"
void __cgo_f_26_1(void) { __typeof__(__redisAsyncCopyError) *__cgo_undefined__; }
#line 26 "not-type"
void __cgo_f_26_2(void) { __redisAsyncCopyError *__cgo_undefined__; }
#line 26 "not-const"
void __cgo_f_26_3(void) { enum { __cgo__undefined__ = (__redisAsyncCopyError)*1 }; }
#line 27 "not-declared"
void __cgo_f_27_1(void) { __typeof__(redisGoroutineAttach) *__cgo_undefined__; }
#line 27 "not-type"
void __cgo_f_27_2(void) { redisGoroutineAttach *__cgo_undefined__; }
#line 27 "not-const"
void __cgo_f_27_3(void) { enum { __cgo__undefined__ = (redisGoroutineAttach)*1 }; }
#line 28 "not-declared"
void __cgo_f_28_1(void) { __typeof__(free) *__cgo_undefined__; }
#line 28 "not-type"
void __cgo_f_28_2(void) { free *__cgo_undefined__; }
#line 28 "not-const"
void __cgo_f_28_3(void) { enum { __cgo__undefined__ = (free)*1 }; }
#line 29 "not-declared"
void __cgo_f_29_1(void) { __typeof__(redisCommandArgv) *__cgo_undefined__; }
#line 29 "not-type"
void __cgo_f_29_2(void) { redisCommandArgv *__cgo_undefined__; }
#line 29 "not-const"
void __cgo_f_29_3(void) { enum { __cgo__undefined__ = (redisCommandArgv)*1 }; }
#line 30 "not-declared"
void __cgo_f_30_1(void) { __typeof__(redisAsyncSetCallbacks) *__cgo_undefined__; }
#line 30 "not-type"
void __cgo_f_30_2(void) { redisAsyncSetCallbacks *__cgo_undefined__; }
#line 30 "not-const"
void __cgo_f_30_3(void) { enum { __cgo__undefined__ = (redisAsyncSetCallbacks)*1 }; }
#line 31 "not-declared"
void __cgo_f_31_1(void) { __typeof__(redisConnectUnix) *__cgo_undefined__; }
#line 31 "not-type"
void __cgo_f_31_2(void) { redisConnectUnix *__cgo_undefined__; }
#line 31 "not-const"
void __cgo_f_31_3(void) { enum { __cgo__undefined__ = (redisConnectUnix)*1 }; }
#line 32 "not-declared"
void __cgo_f_32_1(void) { __typeof__(redisReply) *__cgo_undefined__; }
#line 32 "not-type"
void __cgo_f_32_2(void) { redisReply *__cgo_undefined__; }
#line 32 "not-const"
void __cgo_f_32_3(void) { enum { __cgo__undefined__ = (redisReply)*1 }; }
#line 33 "not-declared"
void __cgo_f_33_1(void) { __typeof__(redisGetReplyType) *__cgo_undefined__; }
#line 33 "not-type"
void __cgo_f_33_2(void) { redisGetReplyType *__cgo_undefined__; }
#line 33 "not-const"
void __cgo_f_33_3(void) { enum { __cgo__undefined__ = (redisGetReplyType)*1 }; }
#line 1 "completed"
int __cgo__1 = __cgo__2;
Change ret to int64 resolve the issue.
My error looks like:-
2016/04/13 13:38:11 Error adding members to set: write tcp 127.0.0.1:56860->127.0.0.1:6379: write: broken pipe
Possible reasons? I don't see anything on Redis's side.
Go 1.1 + osx 10.8.4
conn is a redis client connection:
conn.LPush("list1", 1,2,3)
conn.BRPop(0, "list1")
The BRPop call will not find the already exist value and block forever, it will only work if "list1" is NOT the first key in the call. The following modification will work:
conn.LPush("list1", 1,2,3)
conn.BRPop(0, "", "list1")
Now it crashes with error: Unsupported conversion: redis string to bool
when running HSet inside MULTI
https://github.com/syhpoon/redis/commit/e990d91febc0bc0199f70f9880a27e95459a1f5e
I am having problems handling multiple request using a single instance of redis.Client
.
Maybe is the way I'm using the client (a global instance for all requests), maybe not.
I developed a small project using the Revel framework that reproduces this problem: https://bitbucket.org/rendon/stress_redis
In the same repository I include a script upload.rb
that I did use to stress the server a little bit. You can run it like so:
Term1:
> ./upload.rb 1 1000
Term 2:
> ./upload.rb 1001 2000
If nothing happens the first time, try again and with a bit of luck(?) the problem will arise.
To repeat the test you have to flush the data on Redis, or use a different range if IDs.
If you need more details please just ask :).
Website down, not working. Can't do go get
When a client is connected and using PUBSUB, is there any notification mechanism that the client can use to determine if the connection to redis has dropped?
Don't know whether it is difficult for this implementation,but it will be helpful.
Should write a special compilation line for llvm.
The go get utility does not get the latest master branch (with -u) because there is a "go1" tag in the repo.
"When checking out or updating a package, get looks for a branch or tag that matches the locally installed version of Go. The most important rule is that if the local installation is running version "go1", get searches for a branch or tag named "go1". If no such version exists it retrieves the most recent version of the package."
I'm seeing an issue where I get resp: Invalid input
when I try to retrieve (via LRANGE
) a list of >= 999 elements.
This is on Ubuntu 14.04 / go1.4.1 and the latest gosexy/redis.
I've created a POC program here:
https://gist.github.com/AllYourTexts/f3073468febcb7000273
Test file needs support for configuring test server from command line.
Redis now comes with several Sentinel commands such as:
"sentinel masters" -> list of pods (master+slaves) the sentinel constellation is managing where each master is a key/value sequence of pod-specific information.
"sentinel master " -> returns the information for a specific pod in the same format as the sentinel masters command
"sentinel slaves " -> a key/value sequence giving a list of slaves with per-slave information.
The command "sentinel master cache" (where "cache" is the name of a master being monitored by the sentinel). issued in the CLI will return data along the following format:
127.0.0.1:26379> sentinel master cache
1) "name"
2) "cache"
3) "ip"
4) "127.0.0.1"
5) "port"
... remainder snipped for brevity
Including this in the library via a specific command would greatly increase this use case's simplicity.
However, moving to the command "sentinel masters" you get a list of the above entries:
127.0.0.1:26379> sentinel masters
1) 1) "name"
2) "cache"
3) "ip"
4) "127.0.0.1"
5) "port"
...
2) ....
This too should be parsed into a Struct by the library. Other sentinel commands have this same pattern.
For the Sentinel commands, there is a reason beyond user ease to build this into the library. In order to support Sentinel, and possibly Redis Cluster, the library will need to know this same information in order to select a master to write/read to/from or a collection of slaves to read from.
At an absolute minimum, defining the structs in the library and exporting them for the user to reference would be an improvement.
As far as the command names I'd start with a suggestion of something like
SentinelMaster(name string) -> returns a struct representing a MasterEntry
SentinelMasters() -> Returns a []MasterEntry
InfoStruct(section string) -> returns a Struct for the section given, unless "all" is the section in which case a [] of Structs or an InfoAllStruct which contains each section's struct in it. I suggest InfoStruct to avoid breaking the current Info interface.
In trying to use ConfigGet("maxmemory") I received the error: "resp: Unsupported conversion: array to string"
After making the following modifications to the commands.go file and it worked as expected:
func (c *Client) ConfigGet(parameter string) ([]string, error) {
var ret []string`
err := c.command(
&ret,
[]byte("CONFIG"),
[]byte("GET"),
[]byte(parameter),
)
return ret, err
}
I wonder, why this methods (subscribe, psubscribe) do not return channels, but you should pass one as an argument? Isn't a creation of this channel a boilerplate code?
var err error
client := redis.New()
client.Connect("127.0.0.1", 5010)
_, err = client.RPush("mylist", 1)
fmt.Println(err)
if data length is a lit long it happens.
ConnectNonBlock returns nil even if the connection to the redis server fails.
Steps to reproduce:
Is there a namespace in redis,when I new a namespaced client, all keys that created by the the client will auto add a prefix namespace。Like this
client.Set("a", "b")
, the client is binding to a namespace "test"
。redis will generate a key "test::a"
with value "b"
when I get from redis,Like This
client.Get("a", 'b")
, redis actually return value with the key "test::a"
。
So, we can use redis with multi-projects。I am a newer for golang,I can not contribute code for you.... sorry
Hi,
when i use gosexy/redis HDEL command to delete filed but data exits.
my code:
package main
import (
"fmt"
"log"
"menteslibres.net/gosexy/redis"
)
var host = "127.0.0.1"
var port = uint(6379)
var client *redis.Client
func main() {
var err error
client = redis.New()
err = client.Connect(host, port)
if err != nil {
log.Fatalf("Connect failed: %s\n", err.Error())
return
}
log.Println("Connected to redis-server.")
log.Printf("Sending Hdel...\n")
/*if use d, err := client.HDel("users", "9:user_name") error:Could not Hdel: ERR wrong number of arguments for 'hdel' command
if use d, err := client.HDel("users", "9:user_name", "9:password") no error,but data exit
when i use redis-cli command hdel users 9:user_name 9:passord is ok
*/
d, err := client.HDel("users", "9:user_name", "9:password")
if err != nil {
log.Fatalf("Could not Hdel: %s\n", err.Error())
return
}
log.Printf(fmt.Sprintf("Received %d!\n", d))
client.Quit()
}
thanks
the following
package main
import (
"fmt"
"log"
"menteslibres.net/gosexy/redis"
)
func main() {
var rs *redis.Client = redis.New()
err := rs.Connect("127.0.0.1", 6379)
if err != nil {
log.Printf("Connect failed: %s\n", err.Error())
return
}
_, err = rs.Select(5)
if err != nil {
log.Printf("Could not ping: %s\n", err.Error())
return
}
poolKeys, err := rs.Keys(fmt.Sprintf("pool.%d.*", 25))
if poolKeys != nil && len(poolKeys) > 0 {
for i := 0; i < len(poolKeys); i++ {
log.Printf("key: %s\n", poolKeys[i])
}
log.Printf("total keys: %d\n", len(poolKeys))
}
result, err := rs.Scan(0, []byte("MATCH"), []byte("pool.25.*"), []byte("COUNT"), []byte("10"))
if err != nil {
log.Printf("Could not scan: %s\n", err.Error())
return
}
log.Printf("result: %s\n", result)
}
go1.1 osx 10.8.3
main(86788,0xb4619000) malloc: *** error for object 0x813800: double free
*** set a breakpoint in malloc_error_break to debug
SIGABRT: abort
PC=0x7fff944d0212
signal arrived during cgo execution
menteslibres.net/gosexy/redis._Cfunc_redisCommandArgv(0x507960, 0x4, 0xc200354d00, 0xc200354d20, 0x1d6, ...)
menteslibres.net/gosexy/redis/_obj/_cgo_defun.c:97 +0x2f
menteslibres.net/gosexy/redis.(_Client).command(0xc2000ae380, 0x19af20, 0xc2002c19a8, 0x12140ce0, 0x4, ...)
menteslibres.net/gosexy/redis/_obj/_cgo_gotypes.go:1036 +0x37c
menteslibres.net/gosexy/redis.(_Client).SetEx(0xc2000ae380, 0xc200f13ed0, 0x20, 0xe10, 0x19f720, ...)
menteslibres.net/gosexy/redis/_obj/_cgo_gotypes.go:3001 +0x23b
main.proxyServe(0xc2000afc60, 0xc200d5a180, 0xc200f18630)
/project/works/dnsproxy/src/main.go:121 +0x49a
...
rax 0x0
rbx 0x6
rcx 0xb4618af8
rdx 0x0
rdi 0x11b03
rsi 0x6
rbp 0xb4618b20
rsp 0xb4618af8
r8 0x7fff7d6ba278
r9 0xfffffff0
r10 0x20000000
r11 0x206
r12 0x409000
r13 0x813800
r14 0xb4619000
r15 0x0
rip 0x7fff944d0212
rflags 0x206
cs 0x7
fs 0x0
gs 0x0
you closed Issue #8
but you modify one line
args[2+i] = to.Bytes(fields[i])
you not change
args := make([][]byte, len(fields)+2)
you code:
args := make([][]byte, len(fields)+1) ? right
I tried to connect a server with wrong port.
code:
client := redis.New()
11 err := client.Connect("127.0.0.1",6319)
12
13 if err != nil {
14 log.Fatalf("Connect failed: %s\n", err.Error())
15 os.Exit(1)
16 }
17
18 log.Println("Connected to redis-server.");
19
20 log.Printf("Sedding PING...\n")
21 s, err := client.Ping()
22
23 if err != nil {
24 log.Fatalf("Could not ping: %s\n", err.Error())
25 os.Exit(2)
26 }
27
28 log.Printf("Received %s! \n", s);
got:
2014/04/08 11:35:58 Connected to redis-server.
2014/04/08 11:35:58 Sedding PING...
2014/04/08 11:35:58 Could not ping: Client is not connected.
exit status 1
when run simultaneously It get an error and exit the program.
package models
import (
"errors"
"strconv"
"log"
"menteslibres.net/gosexy/redis"
)
var (
client *r.Client
host = "127.0.0.1"
port = uint(6379)
)
func init(){
client = redis.New()
err := client.Connect(host, port)
if err != nil {
log.Fatalf("Connect failed: %s\n", err.Error())
}
}
type Object struct {
ObjectId string
Score int64
PlayerName string
}
func RGetObject2() (object *Object, err error) {
sl, err := client.HMGet(objectHashName, "ObjectId", "Score", "PlayerName")
if nil != err {
log.Printf("get object from redis hash get error %s", err)
return
}
i, _ := strconv.ParseInt(sl[1], 10, 64)
object = &Object{sl[0], i, sl[2]}
//err = redis.ScanStruct(reply, object)
return
}
SIGSEGV: segmentation violation
PC=0x7f2f1b0b2c54
signal arrived during cgo execution
runtime.cgocall(0x403980, 0x7f2f186812d8)
/usr/local/go/src/pkg/runtime/cgocall.c:149 +0x11b fp=0x7f2f186812c0
menteslibres.net/gosexy/redis._Cfunc_redisCommandArgv(0x2c763e0, 0x5, 0xc210501630, 0xc210501660, 0xa)
menteslibres.net/gosexy/redis/_obj/_cgo_defun.c:104 +0x31 fp=0x7f2f186812d8
menteslibres.net/gosexy/redis.(_Client).command(0xc21001ee10, 0x734a60, 0xc2105b5860, 0xc21060aa80, 0x5, ...)
/home/ice/gopath/src/menteslibres.net/gosexy/redis/main.go:705 +0x364 fp=0x7f2f186813d8
menteslibres.net/gosexy/redis.(_Client).HMGet(0xc21001ee10, 0x8a2510, 0x6, 0x7f2f18681548, 0x3, ...)
/home/ice/gopath/src/menteslibres.net/gosexy/redis/main.go:1530 +0x26d fp=0x7f2f18681480
package main
When using HMGet I was expecting a to receive some values in the return array even if not all fields are valid hash keys (like here: http://redis.io/commands/hmget)
redis> HMGET myhash field1 field2 nofield
In the example below I expect something like this: ["", "*"]. Why do I get an error?
package main
import (
"log"
"menteslibres.net/gosexy/redis"
)
var host = "127.0.0.1"
var port = uint(6379)
var client *redis.Client
func main() {
client = redis.New()
client.Connect(host, port)
client.HMSet("test", "123", "*", "456", "*", "789", "*")
if values, err := client.HMGet("test", "1232", "456"); err == nil {
log.Print("Values: ", values)
} else {
log.Fatal("Error: ", err)
}
client.Quit()
}
Simple test:
package main
import (
"fmt"
"menteslibres.net/gosexy/redis"
)
func main() {
client := redis.New()
client.Connect("localhost", 6379)
info, err := client.Info("all")
fmt.Println(err)
fmt.Println(info)
client.Quit()
}
Output:
Unsupported conversion: redis string to slice
[]
The fix for issue #12 has itself caused a problem: It is now no longer possible to detect via Get() that a key does not exist.
If you GET a non-existent key in Redis, you get a nil value:
127.0.0.1:6379> get nokey
(nil)
To fix issue #12, nil responses from the server were converted to the Go zero-value for a string, which is "" (empty string). However, "" is a valid value for a Redis key:
127.0.0.1:6379> set nokey ""
OK
127.0.0.1:6379> get nokey
""
As such, keys with empty values are now indistinguishable from keys that do not exist. This is a problem.
It is unclear how to fix this without breaking existing client code. One possibility might be a settable option in the Client struct that says how to deal with nil values from the server, and passed as an argument to setReplyValue()...
package main
import (
"fmt"
"menteslibres.net/gosexy/redis"
)
func main() {
var rs *redis.Client = redis.New()
if err := rs.Connect("127.0.0.1", 6379);err != nil {
fmt.Printf("Connect failed: %s\n", err.Error())
}
if _, err := rs.Set("key","value");err != nil {
fmt.Printf("Set failed: %s\n", err.Error())
}
if _, err := rs.SetEx("key",int64(1800),"value");err != nil {
fmt.Printf("SetEx failed: %s\n", err.Error())
}
}
Does each user request is the establishment of a *redis.Client object?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.