Storing byte[ ] as a value with single key in redis using jedis

2,013 views
Skip to first unread message

Guna Sekar

unread,
Jul 4, 2018, 4:33:02 AM7/4/18
to Redis DB
I am currently woking on an assignment where, I have to store an Java object in redis using Jedis. After searching in internet I found that, the only way to do it is, coverting the object into byte[ ]  and store. But with this option, the key also has to be array[ ]. I want the key to be a single value and the value is the byte[ ] 

Юрий Соколов

unread,
Jul 4, 2018, 4:42:07 AM7/4/18
to redi...@googlegroups.com
What prevents you from encoding key as byte[] ? Use any encoding you like: json, message_pack, protobuf.

ср, 4 июл. 2018 г., 11:32 Guna Sekar <dg.gun...@gmail.com>:
I am currently woking on an assignment where, I have to store an Java object in redis using Jedis. After searching in internet I found that, the only way to do it is, coverting the object into byte[ ]  and store. But with this option, the key also has to be array[ ]. I want the key to be a single value and the value is the byte[ ] 

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

Guna Sekar

unread,
Jul 4, 2018, 5:14:03 AM7/4/18
to redi...@googlegroups.com
I want the key to be the plain string

Gunasekar

unread,
Jul 4, 2018, 5:27:49 AM7/4/18
to Redis DB
I have a situation where, the key is sql query and result has to be the sql.ResultSet(java object). Since we can't store an object directly in redis using jedis, I have converted the ResultSet into the byte[ ]. But I want the key to be the same sql query, which is a string.


On Wednesday, July 4, 2018 at 2:44:03 PM UTC+5:30, Guna Sekar wrote:
I want the key to be the plain string

On Wed, Jul 4, 2018 at 2:12 PM Юрий Соколов <funny....@gmail.com> wrote:
What prevents you from encoding key as byte[] ? Use any encoding you like: json, message_pack, protobuf.

ср, 4 июл. 2018 г., 11:32 Guna Sekar <dg.gun...@gmail.com>:
I am currently woking on an assignment where, I have to store an Java object in redis using Jedis. After searching in internet I found that, the only way to do it is, coverting the object into byte[ ]  and store. But with this option, the key also has to be array[ ]. I want the key to be a single value and the value is the byte[ ] 

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

Юрий Соколов

unread,
Jul 4, 2018, 6:18:21 AM7/4/18
to redi...@googlegroups.com
Still could not understand, what is your problem :-(
What prevents you from using "same sql query, which is a string" as a key?
Aside from having large string key is not good for performance of redis, I don't see reason why you can't do it.

ср, 4 июл. 2018 г. в 12:27, Gunasekar <dg.gun...@gmail.com>:
I have a situation where, the key is sql query and result has to be the sql.ResultSet(java object). Since we can't store an object directly in redis using jedis, I have converted the ResultSet into the byte[ ]. But I want the key to be the same sql query, which is a string.

On Wednesday, July 4, 2018 at 2:44:03 PM UTC+5:30, Guna Sekar wrote:
I want the key to be the plain string

On Wed, Jul 4, 2018 at 2:12 PM Юрий Соколов <funny....@gmail.com> wrote:
What prevents you from encoding key as byte[] ? Use any encoding you like: json, message_pack, protobuf.

ср, 4 июл. 2018 г., 11:32 Guna Sekar <dg.gun...@gmail.com>:
I am currently woking on an assignment where, I have to store an Java object in redis using Jedis. After searching in internet I found that, the only way to do it is, coverting the object into byte[ ]  and store. But with this option, the key also has to be array[ ]. I want the key to be a single value and the value is the byte[ ] 

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.

Юрий Соколов

unread,
Jul 4, 2018, 6:23:25 AM7/4/18
to redi...@googlegroups.com
Ahh, I see, it is my fault: I don't know really jedis, and looks like it has interface either `set(string, string)` or `set(byte[], byte[])`....
Well, why calling `sql.getBytes()` bothers you?

ср, 4 июл. 2018 г. в 13:18, Юрий Соколов <funny....@gmail.com>:

Guna Sekar

unread,
Jul 4, 2018, 6:29:29 AM7/4/18
to redi...@googlegroups.com
Jedis is just a component to connect redis from java. The api call is set(byte[ ], byte[ ] ). But I want something like this set(string, byte[ ] )
By the way thanks for your time Yuri Sokolov.. I have to google it to find out your name

Tuan Anh Tran

unread,
Jul 4, 2018, 6:31:42 AM7/4/18
to redi...@googlegroups.com
In that case, I think you have to check jedis documentation instead.

On Wed, Jul 4, 2018 at 5:27 PM, Guna Sekar <dg.gun...@gmail.com> wrote:
Jedis is just a component to connect redis from java. The api call is set(byte[ ], byte[ ] ). But I want something like this set(string, byte[ ] )
By the way thanks for your time Yuri Sokolov.. I have to google it to find out your name

On Wed, Jul 4, 2018 at 3:53 PM Юрий Соколов <funny....@gmail.com> wrote:
Ahh, I see, it is my fault: I don't know really jedis, and looks like it has interface either `set(string, string)` or `set(byte[], byte[])`....
Well, why calling `sql.getBytes()` bothers you?

ср, 4 июл. 2018 г. в 13:18, Юрий Соколов <funny....@gmail.com>:
Still could not understand, what is your problem :-(
What prevents you from using "same sql query, which is a string" as a key?
Aside from having large string key is not good for performance of redis, I don't see reason why you can't do it.

ср, 4 июл. 2018 г. в 12:27, Gunasekar <dg.gun...@gmail.com>:
I have a situation where, the key is sql query and result has to be the sql.ResultSet(java object). Since we can't store an object directly in redis using jedis, I have converted the ResultSet into the byte[ ]. But I want the key to be the same sql query, which is a string.

On Wednesday, July 4, 2018 at 2:44:03 PM UTC+5:30, Guna Sekar wrote:
I want the key to be the plain string

On Wed, Jul 4, 2018 at 2:12 PM Юрий Соколов <funny....@gmail.com> wrote:
What prevents you from encoding key as byte[] ? Use any encoding you like: json, message_pack, protobuf.

ср, 4 июл. 2018 г., 11:32 Guna Sekar <dg.gun...@gmail.com>:
I am currently woking on an assignment where, I have to store an Java object in redis using Jedis. After searching in internet I found that, the only way to do it is, coverting the object into byte[ ]  and store. But with this option, the key also has to be array[ ]. I want the key to be a single value and the value is the byte[ ] 

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+unsubscribe@googlegroups.com.

Юрий Соколов

unread,
Jul 4, 2018, 6:38:05 AM7/4/18
to redi...@googlegroups.com
https://stackoverflow.com/a/16747672/2173542

set( byte[], byte[] ) is more efficient because, when you use String, they are converted in byte[] internally in Jedis before being encoded in the communication buffer.

So, either you will call `set(sqlString.getBytes(), value)`, or (if jedis had `set(string, byte[])`) jedis did it for you.
Currently jedis doesn't have `set(string, byte[])`, so why you don't want call `.getBytes()` by yourself?

ср, 4 июл. 2018 г. в 13:29, Guna Sekar <dg.gun...@gmail.com>:

Guna Sekar

unread,
Jul 4, 2018, 6:55:10 AM7/4/18
to redi...@googlegroups.com
so everytime to retrieve that i have convert the query into byte[] and do it
Reply all
Reply to author
Forward
0 new messages