@@ -804,57 +804,7 @@ namespace redis
804
804
send_ (socket, makecmd (" SETNX" ) << key << value);
805
805
return recv_int_reply_ (socket) == 1 ;
806
806
}
807
-
808
- bool msetnx ( const string_vector & keys, const string_vector & values )
809
- {
810
- assert ( keys.size () == values.size () );
811
-
812
- std::map< int , optional<makecmd> > socket_commands;
813
-
814
- for (size_t i=0 ; i < keys.size (); i++)
815
- {
816
- int socket = get_socket (keys);
817
- optional<makecmd> & cmd = socket_commands[socket];
818
- if (!cmd)
819
- cmd = makecmd (" MSETNX" );
820
- *cmd << keys[i] << values[i];
821
- }
822
807
823
- if ( socket_commands.size () > 1 )
824
- throw std::runtime_error (" feature is not available in cluster mode" );
825
-
826
- typedef std::pair< int , optional<makecmd> > sock_pair;
827
- for (const auto & sp: socket_commands)
828
- {
829
- send_ (sp.first , *sp.second );
830
- recv_ok_reply_ (sp.first );
831
- }
832
- }
833
-
834
- bool msetnx ( const string_pair_vector & key_value_pairs )
835
- {
836
- std::map< int , optional<makecmd> > socket_commands;
837
-
838
- for (size_t i=0 ; i < key_value_pairs.size (); i++)
839
- {
840
- int socket = get_socket (keys);
841
- optional<makecmd> & cmd = socket_commands[socket];
842
- if (!cmd)
843
- cmd = makecmd (" MSETNX" );
844
- *cmd << key_value_pairs[i].first << key_value_pairs[i].second ;
845
- }
846
-
847
- if ( socket_commands.size () > 1 )
848
- throw std::runtime_error (" feature is not available in cluster mode" );
849
-
850
- typedef std::pair< int , optional<makecmd> > sock_pair;
851
- for (const auto & sp: socket_commands)
852
- {
853
- send_ (sp.first , *sp.second );
854
- recv_ok_reply_ (sp.first );
855
- }
856
- }
857
-
858
808
void setex (const string_type & key, const string_type & value, unsigned int secs)
859
809
{
860
810
int socket = get_socket (key);
@@ -1287,35 +1237,7 @@ namespace redis
1287
1237
else
1288
1238
return missing_value ();
1289
1239
}
1290
-
1291
- /* *
1292
- * @warning Not cluster save (all keys must be on the same redis server)
1293
- */
1294
- string_pair brpop (const string_vector & keys, int_type timeout_seconds)
1295
- {
1296
- int socket = get_socket (keys);
1297
- makecmd m (" BRPOP" );
1298
- for (size_t i=0 ; i < keys.size (); i++)
1299
- m << keys[i];
1300
- m << timeout_seconds;
1301
- send_ (socket, m);
1302
- string_vector sv;
1303
- try
1304
- {
1305
- recv_multi_bulk_reply_ (socket, sv);
1306
- }
1307
- catch (key_error & e)
1308
- {
1309
- assert (timeout_seconds > 0 );
1310
- return missing_value (); // should we throw a timeout_error?
1311
- // we set a timeout so we expect that this can happen
1312
- }
1313
- if (sv.size () == 2 )
1314
- return make_pair ( sv[0 ], sv[1 ] );
1315
- else
1316
- return make_pair ( " " , missing_value );
1317
- }
1318
-
1240
+
1319
1241
string_type brpop (const string_type & key, int_type timeout_seconds)
1320
1242
{
1321
1243
int socket = get_socket (key);
@@ -2881,13 +2803,13 @@ namespace redis
2881
2803
};
2882
2804
2883
2805
typedef distributed_base_int<short > distributed_short;
2884
- typedef distributed_base_int<ushort> distributed_ushort;
2806
+ typedef distributed_base_int<unsigned short > distributed_ushort;
2885
2807
2886
2808
typedef distributed_base_int<int > distributed_int;
2887
- typedef distributed_base_int<uint> distributed_uint;
2809
+ typedef distributed_base_int<unsigned int > distributed_uint;
2888
2810
2889
2811
typedef distributed_base_int<long > distributed_long;
2890
- typedef distributed_base_int<ulong> distributed_ulong;
2812
+ typedef distributed_base_int<unsigned long > distributed_ulong;
2891
2813
2892
2814
// TODO: lexical_cast treats int8_t/uint8_t as char/uchar
2893
2815
// typedef distributed_base_int<std::int8_t> distributed_int8;
@@ -2906,189 +2828,6 @@ namespace redis
2906
2828
typedef distributed_base_int<std::int64_t > distributed_int64;
2907
2829
typedef distributed_base_int<std::uint64_t > distributed_uint64;
2908
2830
#endif // NF_NO_INT64_T
2909
-
2910
- #if 0
2911
- // not yet working correctly!
2912
- /**
2913
- * This class provides a subset of the functionality that is provided by distributed_int.
2914
- * As it provides only atomic features and is limited to the things that are required to work without
2915
- * a sequence in redis it is harder to missuse the distributed sequence than it is to missuse shared_int.
2916
- */
2917
- template<typename INT_TYPE>
2918
- class distributed_base_sequence
2919
- {
2920
- public:
2921
- distributed_base_sequence(const client::string_type & name, client & con)
2922
- : shr_int_(name, con)
2923
- {
2924
- }
2925
-
2926
- distributed_base_sequence(const client::string_type & name, INT_TYPE initial_value, client & con)
2927
- : shr_int_(name, initial_value, con)
2928
- {
2929
- }
2930
-
2931
- /**
2932
- * Gets the next free value from the sequence. If no initial_value is given, this starts with 0.
2933
- */
2934
- INT_TYPE get_next_value()
2935
- {
2936
- return cur_val_ = shr_int_++;
2937
- }
2938
-
2939
- INT_TYPE get_global_max_value() const
2940
- {
2941
- return shr_int_-1; // -1 because we work with post increment
2942
- }
2943
-
2944
- inline INT_TYPE get_current_local_value() const
2945
- {
2946
- assert(cur_val_); // You can not call get_current_local_value if you have not called get_next_value
2947
- return *cur_val_;
2948
- }
2949
-
2950
- /**
2951
- * Lets the sequence skip the given count of values.
2952
- */
2953
- void seek(INT_TYPE by)
2954
- {
2955
- INT_TYPE res = (shr_int_ += by);
2956
- return res-1; // -1 because we work with post increment
2957
- }
2958
-
2959
- private:
2960
- distributed_base_int<INT_TYPE> shr_int_;
2961
- boost::optional<INT_TYPE> cur_val_;
2962
- };
2963
-
2964
- typedef distributed_base_sequence<std::intmax_t> distributed_sequence;
2965
-
2966
- #ifndef TIMEOUT_SEC
2967
- #define TIMEOUT_SEC 60
2968
- #endif
2969
-
2970
- /**
2971
- * Supports the Lockable and TimedLockable concepts from Boost.Thread/C++0x.
2972
- */
2973
- class distributed_mutex
2974
- {
2975
- private:
2976
- std::int32_t tstamp_val( std::int32_t nOverSec = 0)
2977
- {
2978
- struct timeval start;
2979
- gettimeofday(&start, NULL);
2980
- int64_t nSec = start.tv_sec;
2981
- int64_t nUSec = start.tv_usec;
2982
-
2983
- return nSec + nOverSec;
2984
- }
2985
-
2986
- std::int32_t GetSystemTime()
2987
- {
2988
- struct timeval start;
2989
- gettimeofday(&start, NULL);
2990
- int64_t nSec = start.tv_sec;
2991
- int64_t nUSec = start.tv_usec;
2992
-
2993
- return nSec;
2994
- }
2995
-
2996
- public:
2997
- distributed_mutex(const client::string_type & name, client & con)
2998
- : con_(&con), name_(name)
2999
- {
3000
- std::string timeout_str = lexical_cast<std::string>( tstamp_val( TIMEOUT_SEC ) );
3001
-
3002
- if( con_->setnx(name_, timeout_str) )
3003
- con_->rpush(name_ + ":list", timeout_str);
3004
- }
3005
-
3006
- ~distributed_mutex()
3007
- {
3008
- }
3009
-
3010
- void lock()
3011
- {
3012
- std::string timeout_tstamp_str;
3013
- while(true)
3014
- {
3015
- timeout_tstamp_str = con_->get(name_);
3016
- std::int32_t timeout_tstamp = lexical_cast<std::int32_t>(timeout_tstamp_str);
3017
- std::int32_t diff = tstamp_val( TIMEOUT_SEC ) - timeout_tstamp;
3018
- if( diff < 1 )
3019
- diff = 1;
3020
- std::string token = con_->blpop(name_ + ":list", diff);
3021
- if( token == client::missing_value() )
3022
- {
3023
- if( timeout_tstamp_str == con_->get(name_) )
3024
- {
3025
- timeout_tstamp_str = lexical_cast<std::string>( tstamp_val( TIMEOUT_SEC ) );
3026
- con_->set(name_, timeout_tstamp_str);
3027
- con_->rpush(name_ + ":list", timeout_tstamp_str);
3028
- }
3029
- continue;
3030
- }
3031
-
3032
- timeout_tstamp_str = con_->get(name_);
3033
- if( token == timeout_tstamp_str )
3034
- break;
3035
- }
3036
-
3037
- std::string new_timeout_tstamp_str = lexical_cast<std::string>( tstamp_val( TIMEOUT_SEC) );
3038
- std::string val = con_->getset(name_, timeout_tstamp_str);
3039
- if( timeout_tstamp_str != val )
3040
- lock();
3041
-
3042
- token_ = new_timeout_tstamp_str;
3043
- }
3044
-
3045
- void unlock()
3046
- {
3047
- con_->rpush(name_ + ":list", token_);
3048
- token_.clear();
3049
- }
3050
-
3051
- bool try_lock()
3052
- {
3053
- if( con_->lpop(name_ + ":list") != client::missing_value() )
3054
- return true;
3055
-
3056
- return false;
3057
- }
3058
-
3059
- bool timed_lock(std::int32_t const& abs_time)
3060
- {
3061
- std::int32_t dur = abs_time - GetSystemTime();
3062
- client::int_type timeout = std::max(dur, 1 );
3063
- std::string res = con_->blpop(name_ + ":list", timeout);
3064
- if( res == client::missing_value() )
3065
- return false;
3066
-
3067
- return false;
3068
- }
3069
-
3070
- template<typename DurationType>
3071
- bool timed_lock(DurationType const& rel_time)
3072
- {
3073
- int32_t dur( rel_time );
3074
- client::int_type timeout = std::max( dur, 1 );
3075
- std::string res = con_->blpop(name_ + ":list", timeout);
3076
- if( res == client::missing_value() )
3077
- return false;
3078
-
3079
- return false;
3080
- }
3081
-
3082
- typedef boost::unique_lock<distributed_mutex> scoped_timed_lock;
3083
- typedef boost::detail::try_lock_wrapper<distributed_mutex> scoped_try_lock;
3084
- typedef scoped_timed_lock scoped_lock;
3085
-
3086
- private:
3087
- client* con_;
3088
- client::string_type name_;
3089
- std::string token_;
3090
- };
3091
- #endif // 0
3092
2831
3093
2832
class distributed_list : public distributed_value
3094
2833
{
0 commit comments