Skip to content

Instantly share code, notes, and snippets.

@markuman
Created January 16, 2019 07:49
Show Gist options
  • Save markuman/7ca165a030065679818d16aca1c3b98a to your computer and use it in GitHub Desktop.
Save markuman/7ca165a030065679818d16aca1c3b98a to your computer and use it in GitHub Desktop.
octave:1> addpath inst
octave:2> which redis
'redis' is a built-in function
octave:3> addpath serialize
octave:4> x(1).a = pi;
octave:5> x(2).a = [1 2 3];
octave:6> x(1).b = 1;
octave:7> x(2).b = {3,4, randi(10,3,3)};
octave:8> x
x =
1x2 struct array containing the fields:
a
b
octave:9> x.a
ans = 3.1416
ans =
1 2 3
octave:10> s = serialize(x)
s = struct("a",{double(3.141592653589793116),double([1 2 3])},"b",{double(1),{double(3),double(4),double([5 8 6;5 3 2;7 3 3])}})
octave:11> r = redis()
r =
<object redis>
octave:12> r.ping()
ans = PONG
octave:13> ret = r.set('my_keyname', s)
ret = OK
octave:14> my_keyname = r.get('my_keyname')
my_keyname = struct("a",{double(3.141592653589793116),double([1 2 3])},"b",{double(1),{double(3),double(4),double([5 8 6;5 3 2;7 3 3])}})
octave:15> x2 = eval(my_keyname)
x2 =
1x2 struct array containing the fields:
a
b
octave:16> x2.a
ans = 3.1416
ans =
1 2 3
octave:17>
127.0.0.1:6379> get my_keyname
"struct(\"a\",{double(3.141592653589793116),double([1 2 3])},\"b\",{double(1),{double(3),double(4),double([5 8 6;5 3 2;7 3 3])}})"
127.0.0.1:6379>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment