@@ -2,7 +2,7 @@ use libc::size_t;
22use std:: convert:: TryFrom ;
33use std:: os:: raw:: c_void;
44use std:: ptr;
5- use std:: string ;
5+ use std:: str :: Utf8Error ;
66use std:: time:: Duration ;
77
88use crate :: from_byte_string;
@@ -74,6 +74,15 @@ impl RedisKey {
7474 } ;
7575 Ok ( val)
7676 }
77+
78+ pub fn hash_get ( & self , field : & str ) -> Result < Option < RedisString > , RedisError > {
79+ let val = if self . is_null ( ) {
80+ None
81+ } else {
82+ hash_get_key ( self . ctx , self . key_inner , field)
83+ } ;
84+ Ok ( val)
85+ }
7786}
7887
7988impl Drop for RedisKey {
@@ -130,6 +139,14 @@ impl RedisKeyWritable {
130139 Ok ( Some ( read_key ( self . key_inner ) ?) )
131140 }
132141
142+ pub fn hash_set ( & self , field : & str , value : RedisString ) -> raw:: Status {
143+ raw:: hash_set ( self . key_inner , field, value. inner )
144+ }
145+
146+ pub fn hash_get ( & self , field : & str ) -> Result < Option < RedisString > , RedisError > {
147+ Ok ( hash_get_key ( self . ctx , self . key_inner , field) )
148+ }
149+
133150 pub fn set_expire ( & self , expire : Duration ) -> RedisResult {
134151 let exp_millis = expire. as_millis ( ) ;
135152
@@ -215,14 +232,23 @@ impl Drop for RedisKeyWritable {
215232 }
216233}
217234
218- fn read_key ( key : * mut raw:: RedisModuleKey ) -> Result < String , string :: FromUtf8Error > {
235+ fn read_key ( key : * mut raw:: RedisModuleKey ) -> Result < String , Utf8Error > {
219236 let mut length: size_t = 0 ;
220237 from_byte_string (
221238 raw:: string_dma ( key, & mut length, raw:: KeyMode :: READ ) ,
222239 length,
223240 )
224241}
225242
243+ fn hash_get_key ( ctx : * mut raw:: RedisModuleCtx , key : * mut raw:: RedisModuleKey , field : & str ) -> Option < RedisString > {
244+ let res = raw:: hash_get ( key, field) ;
245+ if res. is_null ( ) {
246+ None
247+ } else {
248+ Some ( RedisString :: new ( ctx, res) )
249+ }
250+ }
251+
226252fn to_raw_mode ( mode : KeyMode ) -> raw:: KeyMode {
227253 match mode {
228254 KeyMode :: Read => raw:: KeyMode :: READ ,
0 commit comments