Got lots of '\x00' prefix when using StringRedisTemplate - spring-data-redis

I'm putting string to redis server:
stringRedis.opsForValue().set(redisKey, email, ACTIVATION_CODE_TIMEOUT);
But I finally got '\x00\x00\x00\x00 ... my-value' in redis:
Why is this happening?

Sorry about this asking. It's my fault. I made mistakes about using the set()method. The third parameter of set() method is not timeout value. It's offset. To fix it:
stringRedis.opsForValue().set(redisKey, email, ACTIVATION_CODE_TIMEOUT, TimeUnit.SECONDS);

Related

Rebus SqlServerTransportOptions

If you try to Configure SQL Server Transport in Rebus you are encountered with a warning that using a connection string is obsolete and you are directed to use SqlServerTransportOptions.
However I have tried to find any example or code snippet that shows how to do configuration using SqlServerTransportOptions without any success.
Kindly if any body can share a snippet on how to do it properly.
Thanks
Have you tried
Configure.With(activator)
.Transport(t =>
{
var options = new SqlServerTransportOptions(connectionString);
t.UseSqlServer(options, queueName);
})
.Start();
? (where connectionString is your connection string, and queueName is the name of the input queue)
Generally, it should be possible with Rebus to figure things out simply by letting Intellisense and the help tooltips guide you... if it didn't work out for you in this case, I'm very curious to hear what you think is missing.

Blocking get aio_pika

I expected
await queue.get()
to be blocking in aio_pika, but even when I don't set the timeout parameter I instantly get an error:
aio_pika.exceptions.QueueEmpty
Anyway to get a blocking get in aio_pika?
EDIT:
This is the best I could come up with so far.
while True:
msg = await q.get(fail=False)
if msg:
break
await asyncio.sleep(1)
The RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.
You should use a very long timeout, according to the documentation for that method. There does not appear to be another way to do it.

How to check if Telnet connection is still established? using telnetlib

I'd like to check if a connection using the telnetlib is still up.
The way I do it is to send a ls command and check the answer, but I'm sure there must be a smoother solution.
I've got the idea from here, so kudos to them, the code could be something like this
def check_alive(telnet_object):
try:
if telnet_object.sock:
telnet_object.sock.send(telnetlib.IAC + telnetlib.NOP)
telnet_object.sock.send(telnetlib.IAC + telnetlib.NOP)
telnet_object.sock.send(telnetlib.IAC + telnetlib.NOP)
return True
except:
pass
the idea is pretty simple:
if the close() was called .sock will be 0, so we do nothing
otherwise, we try to send something harmless, that should not interact with what ever the underlying service is, the IAC + NOP was a good candidate. LaterEdit: seems that doing the send only once is not enough, so I just did it 3 times, it's not very professional I know, but ... "if it looks stupid, but it works ... than it's not stupid"
if everything goes well we get to the "return True" thous we get our answer, otherwise, the exception will get ignored, and, as there's no return, we will get a None as a response
I've used this method for both direct and proxied(SocksiPy) connections against a couple of Cisco routers

$http returning error response NULL on first call after launch (ionic) everytime, but after subsequent http post its ok

Whenever I launch my app, and click on login on the first few tries, the login will attempt a POST http to the server. However $http always (everytime) returns NULL on first try. sometimes after several few tries still NULL if done fast. But subsequently, its all ok.
I dont get it, why is $http returning error response NULL initially ??
Here is my login controller doing the http post
Login Controller (LoginCtrl)
https://gist.github.com/anonymous/771194bc5815e4ccdf38b57d6158853f
var req = {
method: 'POST',
url: baseURL,
data: postObject,
//timeout: 5000
};
err is NULL here:
}).error(function(err) {
I dont know if it is CORS but I'ved got this set in config.xml
<access origin="*" />
my config.xml
https://gist.github.com/anonymous/b2df3a857338d14ec3fcd6dda776e212
Any ideas ?
Im using ionic 1.7.14
on device iOS 9.3.1
UPDATE
I'ved put the problem code here. can logout first to goto login screen. enter in anything in username/password field, click login once failed, second or third try will be success.
https://github.com/axilaris/ionic_null_http_problem
some troubleshooting so far: i noticed the http post request is called twice. not sure why.
UPDATED the code using $http.post.then but still has the same effect
$http.post(baseURL, postObject).then(function successCallback(response)
response has NULL data --> Object {data: null, status: 0, config: Object, statusText: ""}
It is hard to diagnose having the above details only.
However the problem could be that your handler (login function) is triggered before digest cycle finished updating $scope.data.username and $scope.data.password and for the first tries it sends empty values for those to the server and works fine later.
You can run Safari web inspector to see what is sent to the server to prove this.
The fix may depend on how your view/template is coded. Can you please share it? Or, ideally, create a working sample at http://play.ionic.io/
Another option to fix could be to try to wrap your code related to http request into
$timeout(function() {
// your code goes here
});
or, consider using .$applyAsync() (see the docs for details)
This might help to fix the problem
You are probably getting this inconsistent behavior as you are using the 'success' promise method instead of 'then' (note that use of the success method has now been deprecated).
The key differences between these two methods are:
then() - full power of the promise API but slightly more verbose
success() - doesn't return a promise but offeres slightly more convienient syntax
as highlighted in this answer.
Hence in your scenario, instead of using 'success':
var req = {
method: 'POST',
url: baseURL + 'session/login',
data: postObject,
//timeout: 5000
};
$http(req).success(function(resp) {...
use 'then' along with angular's post shortcut method (you don't have to use this shortcut method, but I think it makes the code more succinct) e.g.:
$http.post(baseURL + 'session/login', postObject).then(function successCallback(response) {
// this callback will be called asynchronously
// when the response is available
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
Using 'then' returns a promise resolved with a value returned from a callback, so it should give you a consistently valid result.
it was a timeout in app.js that caused it. was set to 1 second which gives it it arbitrary success rate.
config.timeout = 1000;

Retrofit errorBody() should return Optional

Let's say I have a test with following assertion:
assertThat(response.isSuccess()).as(response.errorBody().string()).isTrue();
it will throw NullPointerException when response is success therefore test never passes.
I needed to make soemthing like this:
String errorDescription = response.errorBody() == null ? "" : response.errorBody().string();
assertThat(response.isSuccess()).as(errorDescription).isTrue();
which is ugly. Is it possible for errorBody to be wrapped in optional or maybe there is a better way for doing this?
Someone deleted my answer to that saying that I provided only url to github where it was answered. This was my answer to post:
Answered on github of Retrofit: https://github.com/square/retrofit/issues/1304
Optionals are not available on Android.
This time I emphasized actual answer so it will not be deleted again.

Resources