1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

PythonでRedisに保存されたJavaオブジェクトを取得する

Posted at

初めに

javaobj-pyでRedisに保存されたJavaオブジェクトをPythonオブジェクトに変換してみました。手順は以下です。

1.まずredisに接続

PythonでRedisに接続するには、redis-pyというRedisクライアントライブラリを使用します。

import redis
import javaobj.v1 as javaobj

# バイト列のまま:decode_responses=False
connec = redis.Redis((host='Redishost', port=6379, db=0,decode_responses=False)

serialized_java_data = connec.get('MyKey')

#バイト列であることを確認
print(type(serialized_java_data))

2.java objectを取得

# バイト列を読み取る
java_object = javaobj.loads(serialized_java_data)

# java_objectのパラメータvalueをアクセスしてみる(他のパラメータでもいい)
print(java_object.value) 
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?