redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range - jedis

jedis eval script error
script = "return redis.call('hget', KEYS1, ARGV1) ";
o = binaryJedis.eval(script.getBytes(), "hash1".getBytes(), "item1".getBytes());
redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range
at redis.clients.jedis.Protocol.processError(Protocol.java:131)
at redis.clients.jedis.Protocol.process(Protocol.java:165)
at redis.clients.jedis.Protocol.read(Protocol.java:219)
at redis.clients.jedis.Connection.readProtocolWithCheckingBroken(Connection.java:309)
at redis.clients.jedis.Connection.getOne(Connection.java:291)
at redis.clients.jedis.BinaryJedis.eval(BinaryJedis.java:3306)
at RedisHashTest.evalMultiBulkWithBinaryJedis(RedisHashTest.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Disconnected from the target VM, address: '127.0.0.1:55942', transport: 'socket'
enter image description here

String script = "return redis.call('hget', KEYS[1], ARGV[1])";
Integer integer = 1;
Object o = jedis.eval(script.getBytes(), 1, "hash1".getBytes(), "item1".getBytes());

Related

com.ibm.ws.admin.core.jar creating cluster scoped datasource

I am trying to implement "JDBCResourcesWithJMX" sample . In comment it is stated that "code may be configured to: - Create either node or server scoped objects -"
"is there any workaround for using it "cluster" scoped?"
my code part for cluster is below
AdminClient adminClient = AdminClientFactory.createAdminClient(connectProps);
Session session = new Session();
// use node scope to create config objects
ObjectName scope = null;
if (createNodeScopedCfgObjs) {
scope = ConfigServiceHelper.createObjectName(null, "Node", null);
} else { // unless server scope is configured
scope = ConfigServiceHelper.createObjectName(null, "Cluster", "ClusterName");
}
when I pass "cluster" as scoped objects I am getting the below error...
[1/15/18 17:17:55:451 TRT] 000001dd SystemErr R Caused by: com.ibm.websphere.management.exception.InvalidConfigDataTypeException: ADMG0007E: The configuration data type Cluster is not valid.
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at com.ibm.ws.management.configservice.DocAccessor.getTypedObjects(DocAccessor.java:533)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at com.ibm.ws.management.configservice.ConfigServiceImpl.getAllBasic(ConfigServiceImpl.java:2601)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at com.ibm.ws.management.configservice.ConfigServiceImpl.queryConfigObjects(ConfigServiceImpl.java:953)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at java.lang.reflect.Method.invoke(Method.java:620)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:88)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at sun.reflect.GeneratedMethodAccessor51.invoke(Unknown Source)
[1/15/18 17:17:55:460 TRT] 000001dd SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at java.lang.reflect.Method.invoke(Method.java:620)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:292)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at javax.management.modelmbean.RequiredModelMBean$4.run(RequiredModelMBean.java:1261)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at java.security.AccessController.doPrivileged(AccessController.java:426)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:92)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at javax.management.modelmbean.RequiredModelMBean.invokeMethod(RequiredModelMBean.java:1255)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at javax.management.modelmbean.RequiredModelMBean.invoke(RequiredModelMBean.java:1093)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:832)
[1/15/18 17:17:55:461 TRT] 000001dd SystemErr R at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:814)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at com.ibm.ws.management.AdminServiceImpl$1.run(AdminServiceImpl.java:1350)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at com.ibm.ws.security.util.AccessController.doPrivileged(AccessController.java:118)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at com.ibm.ws.management.AdminServiceImpl.invoke(AdminServiceImpl.java:1243)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at com.ibm.ws.management.connector.AdminServiceDelegator.invoke(AdminServiceDelegator.java:181)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at sun.reflect.GeneratedMethodAccessor56.invoke(Unknown Source)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:56)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at java.lang.reflect.Method.invoke(Method.java:620)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at com.ibm.ws.management.connector.soap.SOAPConnector.invoke(SOAPConnector.java:488)
[1/15/18 17:17:55:462 TRT] 000001dd SystemErr R at com.ibm.ws.management.connector.soap.SOAPConnector.service(SOAPConnector.java:324)
[1/15/18 17:17:55:463 TRT] 000001dd SystemErr R at com.ibm.ws.management.connector.soap.SOAPConnection.handleRequest(SOAPConnection.java:65)
[1/15/18 17:17:55:463 TRT] 000001dd SystemErr R at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:733)
[1/15/18 17:17:55:463 TRT] 000001dd SystemErr R at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:522)""
ServerCluster is the keyword. below is the complete code
scope = ConfigServiceHelper.createObjectName(null, "ServerCluster", "ClusterName");

signal: killed at the end of function

Using go-gin I have this function to receive posted jokes and saved them to database:
func PostJoke(c *gin.Context) {
var err error
userId, userName, userAvatar := shared.GetUserInfo(c)
if userId == 0 {
c.JSON(403, gin.H{"error": "not authorized"})
}
title := c.PostForm("title")
content := c.PostForm("content")
nsfwSt := c.PostForm("nsfw")
nsfw, err := strconv.Atoi(nsfwSt)
if err != nil {
log.Panic(err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
}
file, err := c.FormFile("file")
if err != nil {
log.Println(err)
c.String(http.StatusBadRequest, fmt.Sprintf("get form err: %s", err.Error()))
return
}
dir, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
filename := path.Join(shared.RandString(6) + path.Ext(file.Filename))
dest := dir + "/media/photos/" + filename
if err := c.SaveUploadedFile(file, dest); err != nil {
c.String(http.StatusBadRequest, fmt.Sprintf("upload file err: %s", err.Error()))
return
}
_, err = shared.Dbmap.Exec("INSERT INTO joke (user_id, username, user_avatar, title, content, photo, nsfw) VALUES (?, ?, ?, ?, ?, ?, ?)", userId, userName, userAvatar, title, content, filename, nsfw)
if err != nil {
log.Println(err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal server error"})
}
fmt.Println("end of function")
c.JSON(http.StatusOK, gin.H{"sccess": "joke is created"})
}
The function works as expected: saves the data and returns "sccess": "joke is created"
However at the end I receive this mysterious error at the terminal:
signal: killed
and does not respond anymore.
I'm wondering what can cause this and how to fix it?
UPDATE:
go version go1.8.3 linux/amd64
and here is my go env:
me#pc:~$ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/me/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build842411537=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
When I try to rebuild all packages using sudo go install -a
, I get:
main.go:8:2: cannot find package "github.com/gin-gonic/contrib/sessions" in any of:
/usr/lib/go-1.6/src/github.com/gin-gonic/contrib/sessions (from $GOROOT)
($GOPATH not set)
main.go:9:2: cannot find package "github.com/gin-gonic/gin" in any of:
/usr/lib/go-1.6/src/github.com/gin-gonic/gin (from $GOROOT)
($GOPATH not set)
main.go:4:2: cannot find package "proj/controller" in any of:
/usr/lib/go-1.6/src/proj/controller (from $GOROOT)
($GOPATH not set)
main.go:5:2: cannot find package "proj/middleware" in any of:
/usr/lib/go-1.6/src/proj/middleware (from $GOROOT)
($GOPATH not set)

go - oauth2 cannot fetch token: bad request

I write a callback handler to login with Google account:
func GoogleCallbackHandler(w http.ResponseWriter, r *http.Request) {
conf:=&oauth2.Config{
ClientID:"700740834863-m4om9r91htn19htq2b6a05fu6vu4j7i5.apps.googleusercontent.com",
ClientSecret:"...-rB",
RedirectURL:"http://localhost:3000/auth/google/callback",
Scopes:[]string{"profile"},
Endpoint:google.Endpoint,
}
fmt.Println(conf.AuthCodeURL("state"))
code := r.URL.Query().Get("code")
token, err := conf.Exchange(oauth2.NoContext, code)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
client := conf.Client(oauth2.NoContext, token)
resp, err := client.Get("https://www.googleapis.com/userinfo/v2/me")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
raw, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var profile map[string]interface{}
if err := json.Unmarshal(raw, &profile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
session, _ := util.GlobalSessions.SessionStart(w, r)
defer session.SessionRelease(w)
session.Set("id_token", token.Extra("id_token"))
session.Set("access_token", token.AccessToken)
session.Set("profile", profile)
// // Redirect to logged in page
http.Redirect(w, r, "/user", http.StatusMovedPermanently)
}
In main, I serve handlers
http.HandleFunc("/",route.IndexHandler)
http.HandleFunc("/auth/google/",route.GoogleCallbackHandler)
http.Handle("/user",negroni.New(
negroni.HandlerFunc(route.IsAuthenticated),
negroni.Wrap(http.HandlerFunc(route.UserHandler)),
))
I encounter the same problem I got with my old question:
oauth2 cannot fetch token: bad request
oauth2: cannot fetch token: 400 Bad Request
Response: {
"error" : "invalid_request",
"error_description" : "Missing required parameter: code"
}
After I asked this question last time, I managed to fix it with my above code, accessing and getting data successfully, but last night it suddenly got this error again, and I don't get why it no longer works after last few days working with totally same code
How can I get the code from AuthCodeURL? Is there any way to get the code for exchanging without redirecting to any other handler? I want to handle all things in just one this handler
I can solve it by adding one more handler
var (
conf *oauth2.Config
)
func GoogleCallbackHandler(w http.ResponseWriter, r *http.Request) {
conf=&oauth2.Config{
ClientID:"700740834863-m4om9r91htn19htq2b6a05fu6vu4j7i5.apps.googleusercontent.com",
ClientSecret:"...-rB",
RedirectURL:"http://localhost:3000/auth/google/callback",
Scopes:[]string{"profile"},
Endpoint:google.Endpoint,
}
http.Redirect(w, r, conf.AuthCodeURL("state"), http.StatusMovedPermanently)
}
func GoogleLoginHandler(w http.ResponseWriter, r *http.Request) {
code := r.URL.Query().Get("code")
token, err := conf.Exchange(oauth2.NoContext, code)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
client := conf.Client(oauth2.NoContext, token)
resp, err := client.Get("https://www.googleapis.com/userinfo/v2/me")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
raw, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
var profile map[string]interface{}
if err := json.Unmarshal(raw, &profile); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
session, _ := util.GlobalSessions.SessionStart(w, r)
defer session.SessionRelease(w)
session.Set("id_token", token.Extra("id_token"))
session.Set("access_token", token.AccessToken)
session.Set("profile", profile)
http.Redirect(w, r, "/user", http.StatusMovedPermanently)
}

Figure source of "invalid memory address ... " with http.client

I learning the go and struggling with this panic error... it working for some time, but soon end up with such exception panic: runtime error: invalid memory address or nil pointer dereference
The function simply iterate over map of proxies until it successfully get the content of the "address". It must be not very idiomatic, especially using map instead of slice and the last return, but I hope that is not the reason of panic crush...
if I omitted something possible important please, let me know, I will update the post, I just do not want to flood it with unnecessary info.
proxies is a struct with map field with methods for concurrent safe read/delete.
func getContent(address string) string {
localProxies := proxies.Get()
for proxy := range localProxies {
proxyUrl, _ := url.Parse("http://" + proxy)
transport := http.Transport{
Dial: dialTimeout,
Proxy: http.ProxyURL(proxyUrl),
}
httpClient := http.Client{Transport: &transport, Timeout: timeout}
req, err := http.NewRequest("GET", address, nil)
if err != nil {
fmt.Println("Request error: ", err.Error())
}
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0")
res, err := httpClient.Do(req)
defer res.Body.Close()
if err != nil {
// fmt.Println("Broken ", proxy)
fmt.Println("Response error: ", err.Error())
proxies.Del(proxy)
continue
}
if res.StatusCode != 200 {
// fmt.Println("Status error: ", res.Status)
proxies.Del(proxy)
continue
}
out, err := ioutil.ReadAll(res.Body)
if err != nil {
fmt.Println("Read error: ", err.Error())
proxies.Del(proxy)
continue
}
return string(out)
}
return "error"
}
go version go1.4.2 linux/amd64
Until I see more information, this is simply a guess based on what I could gather from the code you posted.
The call
res.Body.Close()
should come after your check for error, not before. So change:
res, err := httpClient.Do(req)
defer res.Body.Close()
if err != nil {
...
}
to
res, err := httpClient.Do(req)
if err != nil {
...
}
defer res.Body.Close()

Go: Why does os.Getwd() sometimes fail with EOF

package main
import "os"
import "fmt"
func main() {
_, err := os.Getwd()
if err != nil {
fmt.Println(err)
}
}
This sometimes prints an error of EOF. Does anyone know why? There's usually some os.Chdir happening before, but that doesn't error out.
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread -fno-common"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
go version go1.0.3
This is a bug in os.Getwd that causes it to return EOF as error when the working directory no longer exists, on platforms that don't support the getwd syscall. Here is a repeatable test case on OS X.
package main
import "os"
import "fmt"
const DIR = "/tmp/somedir"
func main() {
os.Remove(DIR)
if err := os.Mkdir(DIR, 0755); err != nil {
fmt.Println(err)
return
}
if err := os.Chdir(DIR); err != nil {
fmt.Println(err)
return
}
if err := os.Remove(DIR); err != nil {
fmt.Println(err)
return
}
wd, err := os.Getwd()
fmt.Println("err:", err)
fmt.Println("wd:", wd)
}
Output:
err: EOF
wd:

Resources