MATLAB操作redis
- 2020 年 2 月 19 日
- 筆記
redis是一個key-value存儲系統。它支援存儲的value類型更多,包括string(字元串)、list(鏈表)、set(集合)、zset(sorted set –有序集合)和hash(哈希類型)。這些數據類型都支援push/pop、add/remove及取交集並集和差集及更豐富的操作,而且這些操作都是原子性的。在此基礎上,redis支援各種不同方式的排序。為了保證效率,數據都是快取在記憶體中。redis會周期性的把更新的數據寫入磁碟或者把修改操作寫入追加的記錄文件。
對比MySQL資料庫,redis的安裝要比較方便,bing搜索都可以找到安裝方法
這裡介紹一個在MATLAB中操作redis的工具https://github.com/dantswain/redis-matlab
也可以在
https://gitee.com/sickle12138/redis-matlab
更方便的拉取
將src文件夾加入搜索路徑之後就可以使用,目前只支援String(字元串)和Hash(哈希)結構
這裡是測試
function test()
global R;
%將src文件夾加入搜索路徑
addpath('../src')
[R, M] = redisConnection();
assert_string(M, 'OK');
[Value, R, M] = redisPing(R);
assert_string(Value, 'PONG');
[R, M] = redisSet(R, 'foo', 'bar');
assert_string(M, 'OK');
[R, M] = redisSet(R, 'foo', 1234);
assert_string(M, 'ERROR – SET VALUE MUST BE A STRING');
[Value, R, M] = redisGet(R, 'foo');
assert_string(M, 'OK');
assert_string(Value, 'bar');
% 只輸出值
S = redisGet(R, 'foo');
assert_string(Value, 'bar');
redisDisconnect(R);
assert_string(R.status, 'closed');
disp('All tests passed!')
function assert_string(s1, s2, msg)
if nargin == 2,
msg = 'Error!';
end
if (iscell(s1))
assert(strcmp(s1, s2) ~= 0, sprintf('Expected %s == %s', s1{1}, s2))
else
assert(strcmp(s1, s2) ~= 0, sprintf('Expected %s == %s', s1, s2))
end
function assert(cond, msg)
global R;
if nargin == 1,
msg = 'Error!';
end
if ~cond,
fclose(R);
error(msg)
end

想獲取知識但是一些網站卻打不開、影片點開來只能看到一行網址,輸入我的邀請碼 MCGK3X 你我都能獲得額外三個月的藍燈專業版!暢通無阻、立即下載https://github.com/getlantern/forum
幫你學MatLab