Skip to content

Instantly share code, notes, and snippets.

@mtornwall
Created July 9, 2012 14:39
Show Gist options
  • Save mtornwall/3076921 to your computer and use it in GitHub Desktop.
Save mtornwall/3076921 to your computer and use it in GitHub Desktop.
riak+utf8 index weirdness
#!/usr/bin/env escript
%% -*- coding: utf-8 -*-
%% TODO: Set up paths to riakc, riak_pb and protobuffs below.
%%! -pa /path/to/riakc, riak_pb and protobuffs
%% My output:
%% Indices before put: [{"band_bin","Mötley Crüe"}].
%% Indices after put: [{"band_bin",
%% [77,195,131,194,182,116,108,101,121,32,67,114,195,131,
%% 194,188,101]}].
-define(RIAK_HOST, "127.0.0.1").
-define(RIAK_PORT, 8087).
-define(BUCKET, <<"lambda">>).
-define(KEY, <<"Eva Lu Ator">>).
-define(INDEX_NAME, "band_bin").
-define(INDEX_VALUE, "Mötley Crüe").
main(_LesArgs) ->
{ok, Pid} = riakc_pb_socket:start_link(?RIAK_HOST, ?RIAK_PORT),
Obj = riakc_obj:new(?BUCKET, ?KEY),
Md = riakc_obj:get_update_metadata(Obj),
Md2 = dict:store(<<"index">>, [{?INDEX_NAME, ?INDEX_VALUE}], Md),
Obj2 = riakc_obj:update_metadata(Obj, Md2),
Md3 = riakc_obj:get_update_metadata(Obj2),
io:format("Indices before put: ~p.~n", [dict:fetch(<<"index">>, Md3)]),
Obj3 = riakc_obj:update_value(Obj2, <<"ohai">>), % must have value to put
ok = riakc_pb_socket:put(Pid, Obj3),
{ok, StoredObj} = riakc_pb_socket:get(Pid, ?BUCKET, ?KEY),
StoredMd = riakc_obj:get_metadata(StoredObj),
io:format("Indices after put: ~p.~n", [dict:fetch(<<"index">>, StoredMd)]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment